Solved

little .htaccess redirection

Posted on 2012-04-04
6
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

738 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