0

I am trying to add English version to my website in subdomain level as following:

  • en.mywebsite.com/business-name : This will show the English version of a sub-page.

Right now I have actually achieved it somehow by appending the subdomain to the query string with the following code:

Options -Indexes

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com [NC]
RewriteCond %{HTTP_HOST} !^en\.mywebsite\.com [NC]
RewriteRule (.*) http://www.mywebsite.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^en\.mywebsite\.com
RewriteRule ^(.*)$ http://www.mywebsite.com/$1?language=en [QSA]

The problem is, it is doing it by redirecting the user to www.mywebsite.com/business-name?language=en, but I want to avoid redirection, and pass the "newly generated" query string virtually instead.

Can it be achieved, or does QSA always redirect?

Thanks in advance.

Uğur
  • 13
  • 2
  • It will **always** redirect if the rewrite rule is to another domain. en.example.com and www.example.com are not the same. So apache will redirect regardless of whether the R flag is present or not. You will probably have to proxy with P flag if you don't want redirect. – Panama Jack Oct 13 '15 at 16:15

1 Answers1

0

Try changing your last rule from:

RewriteCond %{HTTP_HOST} ^en\.mywebsite\.com
RewriteRule ^(.*)$ http://www.mywebsite.com/$1?language=en [QSA]

to

RewriteCond %{HTTP_HOST} ^en\.mywebsite\.com
RewriteCond %{QUERY_STRING} !language=
RewriteRule ^(.*)$ /$1?language=en [L,QSA]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220