Petr Šrámek
Petr Šrámek

Reputation: 433

Mod_Rewrite Error 310 TOO_MANY_REDIRECTS

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.

Upvotes: 2

Views: 1309

Answers (1)

Oussama Jilal
Oussama Jilal

Reputation: 7739

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]

Upvotes: 3

Related Questions