Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm setting up a multilanguage website and I would like to have your help to take the best decision as regard SEO. After reading this.

I would like to change my URLs from this form www.mywebsite.com/page?lang=es to www.mywebsite.com/es/page?lang=es. I need to keep the ?lang=es for other things.

My .htaccess file already contains these things (to remove .php extension of page.php).

RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]

RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule . %{REQUEST_URI}.php [PT]
share|improve this question

2 Answers 2

Something like this will work.

RewriteCond %{QUERY_STRING} ^(lang=es)$
RewriteRule ^$ /es/page.php?lang=es
RewriteRule ^index.php$ /es/page.php?lang=es

Since you can't match against a query string inside a rewrite rule we utilize %{QUERY_STRING}. If you use a relative path, as in the example, you will get a silent redirect (eg. the URL will not change, but apache will serve the new page). If you want a 301 redirect you will have to use the full FQDN URL including the protocol, such as http://www.example.com/es/page.php?lang=es.

share|improve this answer

This isn't really an answer to the question, but you may want to bear in mind that Google's guidelines says to avoid using URLs with parameter strings in, for languages or other wise.

So If your making the effort of tidying up your URLs you might as well follow best practices.

Google Guidlines URL structure

Google Guidlines Multilingual sites and URL structure

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.