how to load my subdomain contents inside my "sub-subdomain" without redirect

37 Views Asked by At

i have a subdomain for my blog, but i serve two different languages and as far as i know it is good for seo to put every language in a separate subdomain and because of that i made "sub-subdomain"

i wish to load my subdomain english content inside my "sub-subdomain" ( without changing the url or redirect it ), i think this will be more easier for me than make another copy of files from my subdomain to sub-subdomain

this is my code but it doesn't work, btw .. i use lightspeed server

RewriteEngine On
RewriteCond %{HTTP_HOST} ^en.blog\.example\.com  [NC]
RewriteRule ^(.*)$ https://blog.example.com/en/$1 [L]

i want this ( en.blog.example.com ) to load the content of this ( blog.example.com/en/ )

and ( en.blog.example.com/backlinks ) to load the content of this ( blog.example.com/en/backlinks ) .. etc

regards

1

There are 1 best solutions below

1
MrWhite On

Assuming the language subdomain points to the same place that the parent hostname (ie. blog.example.com) then...

RewriteCond %{HTTP_HOST} ^en.blog\.example\.com  [NC]
RewriteRule ^(.*)$ https://blog.example.com/en/$1 [L]

By specifying an absolute URL (ie. with scheme + hostname) in the substitution string this will implicitly trigger a 302 (temporary) redirect and the URL will change.

You need an internal rewrite instead. But you also need to avoid rewriting URLs that are already for the language subdirectory. For example:

RewriteCond %{HTTP_HOST} ^en.blog\.example\.com [NC]
RewriteRule !^en(/|$) en%{REQUEST_URI} [L]

The RewriteRule pattern first checks that the URL-path is not already /en (or does not start /en/) and if the request is for the en subdomain rewrites the request to the /en subdirectory.

However, you would still need to prevent the user from accessing the /en subdirectory from the en subdomain, etc.