little .htaccess redirection

is it possible to redirect automaticaly
www. website.com to www.website.com/fr
how ?
jerrrrryAsked:
Who is Participating?
 
Steve BinkConnect With a Mentor Commented:
@ahoffmann: You are correct, sir.  That should have been %{REQUEST_URI}.
0
 
PapertripCommented:
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

0
 
Steve BinkCommented:
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

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
ahoffmannCommented:
# "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)
0
 
jerrrrryAuthor Commented:
how would it work for localhost test?
thanks
0
 
ahoffmannCommented:
I guess you simply can comment out

# RewriteCond  %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.