Redirection help please

Discuss practical ways rearrange URLs using mod_rewrite.

Redirection help please

Postby leony » Sun Jun 22, 2008 10:29 am

Hi,

I converted contact.php into contact.html using the following rule: (and the rest of the pages as well)

Code: Select all
RewriteRule ^(.*).\html$ /$1.php [L]


However, if someone requests contact.php again, I want them redirect to contact.html. If I use the following, it creates loop naturally. Please help.

Code: Select all
RewriteRule ^(.*).\html$ /$1.php [L]
RewriteRule ^(.*).\php$ /$1.html [R=301,L]
leony
 
Posts: 2
Joined: Sun Jun 22, 2008 10:24 am

Postby richardk » Sun Jun 22, 2008 2:42 pm

Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$

stops loops. When it matches, it means it is not a sub request.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+\.)php$ /$1html [R=301,L]

RewriteRule ^(.+\.)html$ /$1php [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby leony » Mon Jun 23, 2008 3:29 am

Hi,

Thank you very much for your reply. because I am new to this, I need help.

How about this rule?
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^product\.php/parent_id\=12$ /new-product.html [R=301,L]

RewriteRule ^new-product.\html$ /product.php/parent_id=12 [QSA,L]


It doesnt work properly, am I missing something here?
leony
 
Posts: 2
Joined: Sun Jun 22, 2008 10:24 am

Postby richardk » Tue Jun 24, 2008 2:06 pm

Try
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^product\.php/parent_id=12$ /new-product.html [R=301,L]

RewriteRule ^new-product\.html$ /product.php/parent_id=12 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 69 guests

cron