如何在不重定向的情况下将我的子域内容加载到我的“子子域”中。

huangapple go评论58阅读模式
英文:

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

问题

我有一个博客的子域名,但我提供两种不同的语言,据我所知,为了优化搜索引擎排名,最好将每种语言放在单独的子域名中,因此我创建了一个"子子域名"。

我希望在"子子域名"中加载我的子域名英语内容(不改变URL或重定向),我认为这对我来说比将文件从子域名复制到子子域名更容易。

这是我的代码,但它不起作用,顺便说一句,我使用的是Lightspeed服务器。

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

我希望(en.blog.example.com)加载此内容(blog.example.com/en/)

以及(en.blog.example.com/backlinks)加载此内容(blog.example.com/en/backlinks)等等

问候

英文:

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

得分: 1

Assuming the language subdomain points to the same place that the parent hostname (i.e., 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 (i.e., 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.

英文:

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.

huangapple
  • 本文由 发表于 2023年5月18日 02:08:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76275042.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定