1

Sigh... I tried constructing some rewrite rules based on the following Stack Overflow questions: Question 1 Question 2

My .htaccess currently looks like this:

RewriteEngine On 
RewriteBase /

RewriteCond %{REQUEST_URI} !^/(en|fr|es|de)/
RewriteRule ^(.*)$ /en/$1 [R,L]

RewriteRule ^(en|fr|es|de)/(.*)$  $2?locale=$1 [L]

and I've tried all sorts of variations (including the exact answers given in the questions).

As it stands my URL is redirecting to:

/en/?locale=en

When I look at the root with what looks like an infinite redirect loop in Firefox ('The page isn't redirecting properly').

As you've probably guessed I want it to rewrite to /en/ on the root and for it to look like that in the browser. But I want the real url to be /?locale=en. There is an index.php there on the root. Maybe I need another rule to take that into account?

I don't know, I'm really tired and exasperated and .htaccess has always been my downfall. Any insight appreciated.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Varrick
  • 627
  • 1
  • 6
  • 11

1 Answers1

2

You need to make sure there's no locale query string in your first rule:

RewriteCond %{QUERY_STRING} !locale=
RewriteCond %{REQUEST_URI} !^/(en|fr|es|de)/
RewriteRule ^(.*)$ /en/$1 [R,L]

Or you can try:

RewriteCond %{THE_REQUEST} \ /+(?!(en|fr|es|de)/).*
RewriteRule ^(.*)$ /en/$1 [R,L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220