views:

39

answers:

1

If no language parameter is present in the url of my site, I'd like to force a redirect to the English version of the site. My urls are as such:

http://localhost:8888/site_name/products http://localhost:8888/site_name/products/a-nice-product

etc

If there is no "en", "fr" or "nl" after /site_name/ id like htaccess to redirect it to whatever the current url is BUT with an "en" added after /site_name/.

How would one go about this with an .htaccess file?

The current .htaccess rules are

RewriteEngine On
RewriteBase /site_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /site_name/index.php?$1 [L]
+1  A: 

Try this mod_rewrite code:

RewriteEngine on
RewriteCond $2 !^(en|fr|nl)/
RewriteRule ^([^/]+)/(.*) $1/en/$2 [L,R=301]

Edit    Now that you’re already in /site_name/, try this rule:

RewriteCond $1 !^(en|fr|nl)$
RewriteRule ^([^/]+)/.* /site_name/en/$0 [L,R=301]
Gumbo
not working, I think a conflict with the current htaccess rules. Depending on where I paste your rules I get either nothing or internal server error.
stef
@stef: Oh, so you’re already in `/site_name/`. You should have said that.
Gumbo
actually, it's also rewriting the paths to my images. How can I get it to ignore your rules if something is coming out of site_name/images/ ?
stef
@stef: Add another condition: `RewriteCond $1 !^images$`
Gumbo
perfect, thanks alot and happy new year!
stef