Solved

little .htaccess redirection

Posted on 2012-04-04
6
363 Views
Last Modified: 2013-12-25
is it possible to redirect automaticaly
www. website.com to www.website.com/fr
how ?
0
Comment
Question by:jerrrrry
6 Comments
 
LVL 21

Expert Comment

by:Papertrip
ID: 37809271
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
 
LVL 50

Expert Comment

by:Steve Bink
ID: 37809407
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37809654
# "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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:jerrrrry
ID: 37810638
how would it work for localhost test?
thanks
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37810682
I guess you simply can comment out

# RewriteCond  %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 37814294
@ahoffmann: You are correct, sir.  That should have been %{REQUEST_URI}.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now