Mod_Rewrite Error 310 TOO_MANY_REDIRECTS

故事扮演 提交于 2019-12-12 18:35:23

问题


I want make pretty URL (contact.php?id=something to contact/something) with this code in .htaccess, but when I use it my browser displays error 310 - too many redirects.

Options +FollowSymlinks

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^contact/(.*)$ contact.php?id=$1 [L]

RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^contact.php$ /contact/%1? [R,L]

Can somebody help me, what is wrong? Thanks.


回答1:


You problem is that you are redirecting contact/ to contact.php then redirecting contact.php to contact (see the infinite loop ?)

To fix this you can just add another useless parameter to the first rule (another thing is that you should use R=301 in the last rule instead of just R flag, this mean that the redirection is permanant and not temporary, but that's not causing any issue) :

Options +FollowSymlinks

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^contact/(.*)$ contact.php?id=$1&r=0 [L]

RewriteCond %{QUERY_STRING} ^id=([^\&]*)$
RewriteRule ^contact.php$ /contact/%1? [R=301,L]


来源:https://stackoverflow.com/questions/12197749/mod-rewrite-error-310-too-many-redirects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!