2

I have a website www.example.es, with this structure:

www.example.es
index.php
404.html
somepage.html

www.example.es/en
index.php
404.html
somepage.html

I want to redirect any language but es to the english version.

With these rules

RewriteCond %{HTTP:Accept-language} !^(es).* [NC]
RewriteRule ^$ http://www.example.es/en/ [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en)/ en/404.html [L]

If I go to www.example.es with the browser set to english language I see www.example.es/en, and if I go to www.example.es/en/sjhguj I get the correct 404 page. But I want to extend that behavior to every page, so www.example.es/somepage.html needs to have a redirect to www.example.es/en/somepage.html, and so on.

These rules are not working

RewriteCond %{HTTP:Accept-language} !^(es).* [NC]
RewriteCond %{REQUEST_URI} !^en/.*$ [NC]
RewriteRule ^/(.*)$ en/$1 [R=301,L]

There is another way? or I need this structure

www.example.es
es
en

and in every folder the corresponding files?

  • I would avoid redirecting based on "accept-language" headers. They are not very reliable in my experience. I prefer putting a notice on the page saying "Would you like to visit the English site instead? click here". That allows somebody to stay on the Spanish site even if their browser doesn't know they speak Spanish. – Stephen Ostermiller May 7 '18 at 15:39
  • If you are hoping to get traffic from Google, then having English content on a .es domain won't work well. Google only shows .es domains for users in Spain and there is nothing you can do to convince Google otherwise. The only English traffic you will get from Google is English speakers in Spain. – Stephen Ostermiller May 7 '18 at 15:40
  • @StephenOstermiller There is a language selector in the footer section of the page, do you mean to use js to read the browser language e pop up a message? For google well, I don't hope to get traffic, it is only a courtesy, and because most of the time this website is going to be visited from a link, I don't think is going to get something from organic search. – AskaNor_29 May 7 '18 at 16:20
  • Either JavaScript or server side logic can be used to put a message like that in the page. If your site isn't going to depend on Google, then I don't see other problems with your URL structure. – Stephen Ostermiller May 7 '18 at 17:08
  • The only problem is when a user, for some reason, goes to example.es/somepage.html and he isn't redirected to example.es/en/somepage.html. Even with the footer language selector, I think that is better to redirect the non-"es" users to the english language. – AskaNor_29 May 8 '18 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.