临时重定向302的.htaccess和mod-rewrite匹配前pression [英] Temporary redirect 302 with .htaccess and mod-rewrite matching expression

查看:166
本文介绍了临时重定向302的.htaccess和mod-rewrite匹配前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想匹配AA一堆重定向我的网站,基本上移动到服务器上的不同文件夹中。我需要 http://www.site.com/index.php?page=anypage http://www.site.com/newfolder/index的.php?网页= anypage 。问题是 http://www.site.com/index.php 和的 http://www.site.com/index.php?page=home 应该保持不变。我怎样才能做到这一点?

I'm trying to match a a bunch of redirects for my website with basically moved to a different folder on the server. I need to make http://www.site.com/index.php?page=anypage go to http://www.site.com/newfolder/index.php?page=anypage. The thing is http://www.site.com/index.php and http://www.site.com/index.php?page=home should remain untouched. How can I accomplish this?

我是想在的.htaccess 文件下面,但我affraid犯了一个错误。我真的不知道如何测试这一点,无论是。

I was trying the following in the .htaccess file, but I am affraid to make a mistake. I really don't know how to test this, either.

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^/index.php?page=(.*)$ http://www.site.com/newfolder/index.php?page=$1 [R=302,NC]
RewriteRule ^/index.php?page=home http://www.site.com/index.php?page=home [R=302,NC,L]

现在我想,这是暂时的,所以我应该知道浩扭转这种局面!接下来的一周,链接将不得不再次重定向到根服务器。另外,我应该怎么做才能重新建立正常的重定向??

Now I figured that this is temporary, so I should know ho to reverse it! The next week, the links will have to redirect again to the root server. Also, what should I do to re-establish the normal redirection??

推荐答案

如果我已经按照你的正常情况下,你希望是这样的:

If I've followed your scenario correctly, you want something like this:

RewriteEngine On

RewriteCond %{QUERY_STRING} !=""
RewriteCond %{QUERY_STRING} !page=home
RewriteRule ^index.php /newfolder/index.php [R,L]

至于测试的推移,我preFER尝试排除了本地测试服务器上。如果你有完全控制服务器(这是在本地的情况下),也有一些的mod_rewrite 指令,可以帮助您记录正在发生的事情,这在调试有帮助。 模块文档有更多这方面的信息。

As far as testing goes, I prefer to try rules out on a local test server. If you have full control over the server (as is the case locally), there are some mod_rewrite directives that help you log what's going on, and that can be helpful in debugging. The module documentation has more information about this.

编辑::当你想切换回,修改重写规则上面,像这样:

When you want to switch back, modify the RewriteRule above like so:

RewriteRule ^newfolder/index\.php /index.php [R,L]

这篇关于临时重定向302的.htaccess和mod-rewrite匹配前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆