/X-allow/test.php to /X-allow/test_ro.php

Discuss practical ways rearrange URLs using mod_rewrite.

/X-allow/test.php to /X-allow/test_ro.php

Postby blu » Sun Oct 04, 2009 8:02 am

If a user from Romania visits example.com/X-allow/test.php the rewrite will redirect him to example.com/X-allow/test_ro.php.

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^RO$
RewriteRule ^/var/www(.+)[^_ro].php$ $1_ro.php [R=301,L]


I tried this but does'n work, it redirects to tes_ro.php! I know i made a mistake somewhere, please help!
blu
 
Posts: 2
Joined: Sun Oct 04, 2009 7:53 am

Postby richardk » Sun Oct 04, 2009 8:52 am

The t is being matched by [^_ro]. That is not the right way to do it, the [] only matches one character and [^_ro] means not "_", "r" or "o" so it would not match tester.php fore example.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^RO$
RewriteCond $1 !_ro$
RewriteRule ^/var/www(/.+)\.php$ $1_ro.php [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby blu » Sun Oct 04, 2009 9:01 am

Thank you, very VERY much!

It works with
Code: Select all
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^RO$
RewriteRule ^/var/www([^_]+)[^_ro]?\.php$ $1_ro.php [R=301,L]
but your code is by far more understable, thank you again.

L.E.: What value has $1 from
Code: Select all
RewriteCond $1 !_ro$
?
blu
 
Posts: 2
Joined: Sun Oct 04, 2009 7:53 am

Postby richardk » Sun Oct 04, 2009 10:49 am

L.E.: What value has $1 from
Code: Select all
RewriteCond $1 !_ro$

?

It has the same value as the $1 in the RewriteRule substitution. For /X-allow/test.php it would be "/X-allow/test".
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 27 guests

cron