重定向子域的主域名 [英] Redirect subdomain to main domain
问题描述
我处理,同时支持英语和西班牙语的网站,我想知道如何将所有的请求的特定语言的子域名重定向到主域名(en.mysite.com和es.mysite .COM到mysite.com)。
I'm dealing with a site that supports both English and Spanish, and I'd like to know how to redirect all the requests to the language-specific subdomains to the main domain (en.mysite.com and es.mysite.com to mysite.com).
整个网站在PHP编程,它有一个主脚本的index.php
的处理语言
和部分
GET参数,并显示相应的东西。
The whole site is programmed in PHP and it has a main script index.php
that processes the language
and section
GET parameters and displays stuff accordingly.
现在,我试着做在mysite.com的根.htaccess文件下面。我认为它明确了我想要做的:
Now, I tried to do the following in the .htaccess file in the root of mysite.com. I think it clarifies what I'm trying to do:
RewriteEngine On
# English redirects
RewriteRule ^en.mysite.com$ index.php?language=English§ion=Main
RewriteRule ^en.mysite.com/store$ index.php?language=English§ion=Store
RewriteRule ^en.mysite.com/create_account$ index.php?language=English§ion=CreateAcc
# Spanish redirects
RewriteRule ^es.mysite.com$ index.php?language=Spanish§ion=Feed
RewriteRule ^es.mysite.com/comprar$ index.php?language=Spanish§ion=Store
RewriteRule ^es.mysite.com/crear_cuenta$ index.php?language=Spanish§ion=CreateAcc
但是,这并不正常工作。谁能告诉我我在做什么错在这里?
But this doesn't work. Can anyone tell me what I'm doing wrong here?
推荐答案
您可以不包括主机名匹配在重写规则
,因为它只匹配的一部分针对该URI。你需要使用一个单独的的RewriteCond
,针对该主机名匹配的为您的每个规则的:
You can't include the hostname as part of the match in a RewriteRule
, as it only matches against the URI. You'll need to use a separate RewriteCond
that matches against the hostname for each of your rules:
RewriteCond %{HTTP_HOST} ^en.mysite.com$ [NC]
RewriteRule ^$ /index.php?language=English§ion=Main
RewriteCond %{HTTP_HOST} ^en.mysite.com$ [NC]
RewriteRule ^store$ /index.php?language=English§ion=Store
RewriteCond %{HTTP_HOST} ^en.mysite.com$ [NC]
RewriteRule ^create_account$ /index.php?language=English§ion=CreateAcc
然后重写西班牙语:
Then the spanish rewrites:
RewriteCond %{HTTP_HOST} ^es.mysite.com$ [NC]
RewriteRule ^$ /index.php?language=English§ion=Feed
RewriteCond %{HTTP_HOST} ^es.mysite.com$ [NC]
RewriteRule ^comprar$ /index.php?language=English§ion=Store
RewriteCond %{HTTP_HOST} ^es.mysite.com$ [NC]
RewriteRule ^crear_cuenta$ /index.php?language=English§ion=CreateAcc
这篇关于重定向子域的主域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!