.htaccess重写问题 - 我错过了什么?

时间:2011-12-08 06:19:05

标签: apache .htaccess mod-rewrite

我想做的只是一个非常简单的重定向,以便mypage.html显示在浏览器中,但index.php?s=1是提供的页面。

我在这里缺少什么?

redirect 301 /mypage.html index.php?s=1
- 这会按预期重定向整个页面

RewriteRule ^/index.php?s=1$ mypage.html [R=301,L]
- 当我访问mypage.html

时,这会返回404错误

2 个答案:

答案 0 :(得分:1)

是否要将FROM mypage.html重定向到index.php?s = 1?

如果是这种情况,您的RewriteRule输入顺序错误。如果您尝试访问index.php?s = 1,它会将您重定向到mypage.html。

这个蠢蠢欲动(没有保证。我没有测试规则,只是切换了规则中的文件名):

RewriteRule ^mypage.html$ /index.php?s=1 [R=301,L]

答案 1 :(得分:0)

您写道:

浏览器中显示

mypage.html,但index.php?s=1是提供的页面。

如果您想要做的重定向(即客户端浏览器中的网址不会更改),那么您只需制作一个像这样的rwriterule :

RewriteRule ^mypage\.html$ /index.php?s=1 [QSA,L]

没有更多。

现在,如果您希望用户能够输入index.php?s=1,请添加以下规则:

RewriteRule ^/index\.php$ mypage.html [R=301,L]

所以,总而言之:

RewriteRule ^mypage\.html$ /index.php?s=1 [QSA,L]
RewriteRule ^/index\.php$ mypage.html [R=301,L]

希望这有帮助