Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a multilingual site with the root being English and a sub-directory (/es/) being a human translation into Spanish. Instead of manually updating all URLs, I have a opted to use mod_rewrite to update the links. Thus, I have the following snippet of code in the .htaccess file of the /es/ sub-folder:

# English -> Spanish redirects
RewriteBase /es/
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^company.html$ empresa.html? [R=301,L]
RewriteRule ^products.html$ productos.html? [R=301,L]
# etc...

I have a PHP script running machine translations of all other languages:

# Machine translations
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/([a-z]{2}|zh-CN|zh-TW)/(.*)$ /$1/$3 [R=301,L]
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/([a-z]{2}|zh-CN|zh-TW)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/(.*)$ /translate/translate.php?lang=$1&url=$2 [L,QSA]
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)$ /translate/translate.php?lang=$1 [L,QSA]

However, if translating the Spanish pages, I want to use the English URLs for translation instead of the Spanish URLs. Thus, I have the following code in the .htaccess file of the root directory:

# Spanish -> English redirects
RewriteCond %{REQUEST_URI} !^/es
RewriteRule ^empresa.html$ company.html? [R=301,L]
RewriteRule ^productos.html$ products.html? [R=301,L]
# etc...

The problem is that I am getting an infinite redirect loop when visiting any of the Spanish URLs. If I remove the ES->EN redirects in the root, everything in the /es/ dir works fine. However, I can't seem to get the rewrites of the URLs in the root directory from Spanish -> English. I want to make sure the Spanish URLs are only showing in the ES folder and root and every other (virtual) folder uses the English URLs.

I should note that the ES->EN rewrites are above the machine translation rewrites, though I have tried both ways.

share|improve this question
Try using the <Location> tag? – TheFiddlerWins Sep 3 '13 at 17:46
I don't have access to the .conf file on this server since it is shared hosting. – Michael Yaeger Sep 4 '13 at 0:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.