Htaccess appending to query string with QSA without redirect

481 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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]