Problem with mod_rewrite

Using a single web hosting account to host multiple sites

Problem with mod_rewrite

Postby rgomes » Fri Jun 26, 2009 12:26 am

Hello, i'm having some problems with some mod_rewrite rules that maybe someone can help.

What I'm trying to acomplish is:

When trying to access:
www.example.com/fr/something
It should redirect to:
www.example.fr/fr/something

I have this is working with the following rules:
Code: Select all
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} /fr/
RewriteRule (.*) http://www.example.fr/$1 [R=301,L]
Now the problem is that I'm also trying to do the inverse, that is:

When trying to access:
www.example.fr/something
It should redirect to:
www.example.com/something

The rule that I have in place right now for this is:
Code: Select all
RewriteCond %{HTTP_HOST} ^www.example.fr$
RewriteCond %{REQUEST_URI} !/fr/
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
This is not working though.
With the second rewrite condition above I'm trying to say "when there isn't any country code subfolder it should redirect to the .com"



Any ideas anyone? I'm not too experienced with mod_rewrite or regular expressions so any feedback will be much appreciated.

Thanks.
rgomes
 
Posts: 1
Joined: Fri Jun 26, 2009 12:16 am

Postby richardk » Fri Jun 26, 2009 9:09 am

Are they both supposed to work together?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^fr(/.*)?$ http://www.example.fr/$0 [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?example\.fr$ [NC]
RewriteRule !^fr(/.*)?$ http://www.example.com%{REQUEST_URI} [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 1 guest

cron