[mod_rewrite] 302 Redirect old .php URLs to rewritten ones
Posted: Thu Oct 13, 2011 3:51 pm
Hi everyone. I've got a funny problem with mod_rewrite.
Some time ago I used it to rewrite ugly .php links to nicer ones. Let's assume I only defined a simple index.html -> index.php rule.
Now I want to get rid of old URLs also when users directly type them, I want that when someone point its browser to /index.php, he will be visually redirected (302) to /index.html and display the page. So I tried something like:
But obviously this creates an infinite redirect loop.
How can I achive the behaviour I want?

Some time ago I used it to rewrite ugly .php links to nicer ones. Let's assume I only defined a simple index.html -> index.php rule.
Now I want to get rid of old URLs also when users directly type them, I want that when someone point its browser to /index.php, he will be visually redirected (302) to /index.html and display the page. So I tried something like:
Code: Select all
# Mod Rewrite init
RewriteEngine on
RewriteBase /
# First rule (it works alone)
RewriteRule ^index\.html$ index.php [L,QSA]
# Second rule for redirect old urls to new ones
RewriteRule ^index\.php$ index.html [R=302,L,QSA]How can I achive the behaviour I want?