friendly url without endless loop

Discuss practical ways rearrange URLs using mod_rewrite.

friendly url without endless loop

Postby Gert » Sun Jul 04, 2010 9:32 pm

I'm trying to redirect some static pages like /navigatie/dt_partners.php to /over-sawadee/duurzaam-toerisme/partners/. I've got the following code in .htaccess but it's not working and firefox is saying that the redirect is not properly set up and I'm thinking it must be an endless loop.

RewriteRule ^over-sawadee/duurzaam-toerisme/partners/$ /navigatie/dt_partners.php? [L]
RewriteRule ^navigatie/dt_partners.php$ /over-sawadee/duurzaam-toerisme/partners/? [R=301,NC]

I was hoping that the [L] woud take care of the endless loop but apparently it is not. Anybody got an idea how this can be solved?
Thanks
Gert
 
Posts: 10
Joined: Sun Jul 19, 2009 6:26 pm

Re: friendly url without endless loop

Postby TeckniX » Mon Aug 02, 2010 1:02 pm

You can just add the following before your rules, to make sure no redirect is enforced:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^navigatie/dt_partners.php$ /over-sawadee/duurzaam-toerisme/partners/ [R=301,NC,L]
RewriteRule ^over-sawadee/duurzaam-toerisme/partners/$ /navigatie/dt_partners.php [L]



The above assumes that your end result is to have the link as:
over-sawadee/duurzaam-toerisme/partners/.
TeckniX
 
Posts: 38
Joined: Tue Mar 27, 2007 12:18 pm

Re: friendly url without endless loop

Postby Gert » Mon Aug 02, 2010 4:50 pm

It's working! And your assumption was right.
Thx a lot, TeckniX!

Just read somewhere on the net that {ENV:REDIRECT_STATUS} checks if the redirect status is empty so you don't end up in a loop. Correct?

And how would you combine the redirect status with a query condition? These don't seem to work:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^soortreis=wandelreis$
RewriteRule ^navigatie/soortreis.php /onze-reizen/wandelreis/? [R=301,NC,L]
RewriteRule ^onze-reizen/wandelreis/$ /navigatie/soortreis.php?soortreis=wandelreis [L]
or
RewriteCond %{QUERY_STRING} ^soortreis=wandelreis$
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^navigatie/soortreis.php /onze-reizen/wandelreis/? [R=301,NC,L]
RewriteRule ^onze-reizen/wandelreis/$ /navigatie/soortreis.php?soortreis=wandelreis [L]
Gert
 
Posts: 10
Joined: Sun Jul 19, 2009 6:26 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest

cron