[英].htaccess subdomain redirection to root domain
i just want to ask a quick question about .htaccess. 我只想问一个关于.htaccess的快速问题。
Here's how my webhosting works with subdomains... 以下是我的网站主机如何使用子域名...
Once i create a subdomain... then they create a folder into the root folder like this... 一旦我创建了一个子域...然后他们就像这样在根文件夹中创建一个文件夹......
www.mydomain.com ---> public_html
sub.mydomain.com ---> public_html/sub
What i want to do is... to redirect all request from sub.mydomain.com to www.mydomain.com with some GET variable or something to identify from what subdomain the request is coming from... 我想要做的是......将所有来自sub.mydomain.com的请求重定向到www.mydomain.com并使用一些GET变量或某些东西来识别请求来自哪个子域...
So for example... when i get a requests to work like this 例如......当我得到这样的工作请求时
http://sub.mydomain.com/myphp.php ---> http://www.mydomain.com/myphp.php?comingfrom=sub
http://sub.mydomain.com/(anyUrl) ---> http://www.mydomain.com/(anyUrl)?comingfrom=sub
I'm also wondering if this would execute some .htaccess redirects present in the main domain... 我也想知道这是否会执行主域中存在的一些.htaccess重定向...
Hope you guys could help me... 希望你们能帮助我......
Thanks in advance... 提前致谢...
Put a .htaccess with following content into your subdomain folders: 将包含以下内容的.htaccess放入子域文件夹中:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$ [NC]
RewriteRule ^(.*) http://www.mydomain.com$1?comingfrom=%1 [QSA,R=301,L]
(untested, sorry) (未经测试,抱歉)
EDIT: 编辑:
you pointed out that you would like to keep the subdomain in your addressbar and don't want a redirect. 您指出您希望将子域保留在地址栏中,并且不希望重定向。 So you need to make a view changes to your
<VirtualHost>
of www.mydomain.com like so 因此,您需要对www.mydomain.com的
<VirtualHost>
进行视图更改
<VirtualHost ...:80>
ServerName www.mydomain.com
ServerAlias mydomain.com
ServerAlias sub.mydomain.com
DocumentRoot /path/to/your/docroot/of/www.mydomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$ [NC]
RewriteRule ^(.*) $1?comingfrom=%1 [QSA,PT,L]
</VirtualHost>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.