Link to home
Start Free TrialLog in
Avatar of jerrrrry
jerrrrry

asked on

little .htaccess redirection

is it possible to redirect automaticaly
www. website.com to www.website.com/fr
how ?
Avatar of Papertrip
Papertrip
Flag of United States of America image

Add the following to your VirtualHost config for website.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?website.com$ [NC]
RewriteRule ^(/)?$ fr [R=301,L]

Open in new window

Avatar of Steve Bink
The previous answer will result in an infinite loop.  It will also remove the file requested from the new URL.  Try this instead:

RewriteCond  %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !^/?fr [NC]
RewriteRule ^/?(.*)$ /fr/$1

Open in new window

# "little" improved :)
RewriteCond  %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?fr [NC]
RewriteRule ^/?(.*)$ /fr/$1 [QSA,L]

@routinet, is your REQUEST_FILENAME a typo? (it differs to REQUEST_URI in rare cases)
Avatar of jerrrrry
jerrrrry

ASKER

how would it work for localhost test?
thanks
I guess you simply can comment out

# RewriteCond  %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial