mod_rewrite 301 重定向不起作用
我正在尝试设置一个重写,将此 URL:
/video-2011.php?video=150
重定向到:
/video/150/freeform-title-text-here /
我在 HTACCESS 中使用此行进行了重写:
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [L]
但是一旦我将 R=301 添加到混合中,它就会中断。有什么想法吗?
这是 HTACCESS 崩溃时的完整信息:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [R=301,L]
非常感谢任何帮助,谢谢!
I'm trying to set up a rewrite that will redirect this URL:
/video-2011.php?video=150
to this:
/video/150/freeform-title-text-here/
I have the rewrite working using this line in my HTACCESS:
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [L]
But as soon I add R=301 into the mix, it breaks. Any ideas?
Here's the full HTACCESS when it breaks:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [R=301,L]
Any help is greatly appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的 .Htaccess 中可能缺少一行。
我假设您想要重写 url(如果是:)
和重定向(如果是:) url:
到:
因此,这样可以使 url 看起来漂亮整洁。
如果我错了,请纠正我。
编辑
我添加了 RewriteCond 以阻止第二次重写发生。
因为第一条规则显然会重写:
这意味着您看不到的查询字符串:
也会使第二条规则发生。
I think you might be missing a line from your .Htaccess.
I assuming you want to rewrite the url if it is:
And redirect the url if it is:
to:
So this way it keeps the urls looking pretty and tidy.
Please correct me if I am wrong.
Edit
I've added in a RewriteCond to stop the second rewrite happening.
As the first rule will obviously rewrite:
Which means the query string you don't see:
Would of made the second rule happen too.
您可以尝试吗:
是的,它会将
/video/150/foo
重定向到/video.php?video=150
,而不是您在您的文章中所述的相反方式问题。Can you try:
And yes it will redirect
/video/150/foo
to/video.php?video=150
not the other way around as you've stated in your question.