0

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

Rayan Adams
  • 73
  • 1
  • 7
  • 1
    "as i know it is good for seo to put every language in a separate subdomain" - why do you think that? It's not like you can geo-target a subdomain (unlike a ccTLD). – MrWhite May 17 '23 at 23:22
  • 1
    What do you mean by "doesn't work" exactly? – MrWhite May 17 '23 at 23:25
  • i know my bro, but it really matters in seo because the ( keyword authority ) can help me to rank higher in google, "doesn't work" i mean the rule redirects the "sub-subdomain" to the "subdomain", i only need to show the content of subdomain not to redirect or change the url – Rayan Adams May 18 '23 at 00:43

1 Answers1

1

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.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • i really appreciate your help, but it gives me an error ( ERR_TOO_MANY_REDIRECTS ), please notice that the sub directory ( english folder ) is located on another subdomain – Rayan Adams May 18 '23 at 00:45