Redirect 和 RewriteRule 一起使用时的 .htaccess 重定向循环
我正在 HTACCESS 文件中尝试以下操作:
我想 301 重定向此 --> http://www.domain.com/somepage.php?page=foo
对此——> http://www.domain.com/my-pretty-url/
这有效当我改变网站上的内部链接以阅读我想要的方式并且我不使用 R=301 标志时很好:
RewriteRule ^my-pretty-url/$ /index\.php?page=foo [L]
但是...这里的问题是我还想将任何外部请求 301 重定向到服务器,当我处理时它让我陷入重定向循环。
RewriteCond %{REQUEST_URI} /index.php$
RewriteCond %{QUERY_STRING} ^page=foo$
RewriteRule ^.*$ http://www.domain.com/my-pretty-url/? [R=301,L]
RewriteRule ^my-pretty-url/$ /index\.php?page=foo [L]
RewriteCond 规则本身不起作用,只有底部的单个 RewriteRule 本身可以用于内部重写,但它不处理外部请求。
显然,如果我将两者放在一起,就会形成一个循环。我该如何解决这个问题?
谢谢!
I'm attempting the following in an HTACCESS file:
I want to 301 redirect this --> http://www.domain.com/somepage.php?page=foo
to this --> http://www.domain.com/my-pretty-url/
This works fine when I alter internal links on the site to read how I want and I DO NOT use the R=301 flag:
RewriteRule ^my-pretty-url/$ /index\.php?page=foo [L]
BUT... the hitch here is I also want to 301 Redirect any external requests to the server, which when I handle that it puts me in a redirect loop.
RewriteCond %{REQUEST_URI} /index.php$
RewriteCond %{QUERY_STRING} ^page=foo$
RewriteRule ^.*$ http://www.domain.com/my-pretty-url/? [R=301,L]
RewriteRule ^my-pretty-url/$ /index\.php?page=foo [L]
The RewriteCond rules don't work by themselves, only the single RewriteRule at the bottom works by itself for internal rewrites, but it doesn't handle outside requests.
Obviously, if I have both together, it's creating a loop. How do I get around this??
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试以下方法来防止循环
Try the following to prevent the looping