DarkLeafyGreen
DarkLeafyGreen

Reputation: 70416

htaccess redirect when url does not contain a string

I have following site structure

 - root 
     - de/index.htm
     - en/index.htm

When the user requests the site and has not defined the language like

 mysite.com

instead of

mysite.com/en/

I want him to be redirected to the en folder. Because the root folder does not contain any files actually. I am not really familiar with apache rewrite rules. This is what I tried

RewriteEngine On
RewriteBase / 

RewriteCond RewriteCond %{REQUEST_URI} /
RewriteRule ^/en/index.htm

But this does not work. Any ideas how to solve this?

Upvotes: 1

Views: 1384

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

What you have isn't correct syntax, you've got 2 RewriteCond in a row followed by what looks like the actual condition, then a rule that has no target. Try:

RewriteEngine On
RewriteBase / 
RewriteRule ^/?$ /en/index.htm [L]

If you want what's in the browser's URL address bar to change, add an R flag to the brackets:

RewriteRule ^/?$ /en/index.htm [L,R]

Upvotes: 1

Related Questions