重定向通配符子域的子目录,而不在地址栏URL改变 [英] Redirect wildcard subdomains to subdirectory, without changing URL in address bar
问题描述
我读了很多关于这个问题和答案在这里,但似乎没有解决我的具体问题。
我想任何子域名重定向到子目录匹配。
所以:x.domain.com会去domain.com/x~~V,并y.domain.com会去domain.com/y~~V - 但我想这样做,而不在地址栏更改URL <。 / P>
这是我到目前为止有:
选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST}!^(WWW)\。 [NC]
的RewriteCond%{HTTP_HOST} ^(。*)\。域\ .COM [NC]
重写规则^ /%1 [P,L]
不过,这需要我到一个网站重定向循环,在地址栏所在的子域仍然存在不正确的地址。
例如,x.domain.com带我到x.domain.com/x~~V,我得到重定向循环错误。
我会很感激,如果任何人都可以在正确的方向指向我!我没有任何改变似乎工作...
首先,请确保虚拟主机的正确配置Apache配置和domain.com的所有子域都在同一个主机配置(通配符):
&LT;虚拟主机*:80&GT;
服务器名domain.com
ServerAlias * .domain.com
...
您可以重定向具有以下htaccess的配置工作:
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^(。*)\。域\ .COM
重写规则^(。*)$ http://domain.com/%1/$1 [L,NC,QSA]
现在,如果你打开asd.domain.com它应该重定向你domain.com/asd~~V。 您仍然有问题,该重定向是在URL地址栏中可见。为了prevent这一点,使的mod_proxy(并加载子模块),您的服务器上,并用P标志调换L标记:
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^(。*)\。域\ .COM
重写规则^(。*)$ http://domain.com/%1/$1 [P,NC,QSA]
如果这不起作用,查看虚拟主机的配置和error.log在子域调用的内容会有所帮助!
参考:
的.htaccess重写子域目录
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
http://httpd.apache.org/docs/2.2/rewrite/flags html的#flag_p
I've read a lot of questions and answers about this on here but none that seem to solve my specific problem.
I want to redirect any subdomain to the subdirectory to match.
So: x.domain.com would go to domain.com/x, and y.domain.com would go to domain.com/y - But I want to do this without the URL in the address bar changing.
Here's what I have so far:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC]
RewriteRule ^ /%1 [P,L]
But this takes me to a website redirect loop, with an incorrect address in the URL bar where the subdomain still exists.
For example, x.domain.com takes me to x.domain.com/x and I get a redirect loop error.
I'd be grateful if anyone can point me in the right direction! Nothing I change seems to work...
First of all, make sure that the vhost in the apache configuration is properly configured and all subdomains of domain.com are in the same host configuration (wildcard):
<VirtualHost *:80>
ServerName domain.com
ServerAlias *.domain.com
...
You can get the redirect working with the following htaccess configuration:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/%1/$1 [L,NC,QSA]
Now, if you open asd.domain.com it should redirect you to domain.com/asd. You will still have the problem, that the redirect is visible in the URL address bar. In order to prevent this, enable mod_proxy (and load the submodules) on your server and exchange the "L" flag with the "P" flag:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/%1/$1 [P,NC,QSA]
If this doesn't work, viewing the vhost configuration and the content of error.log on subdomain calling will be helpful!
References:
.htaccess rewrite subdomain to directory
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_p
这篇关于重定向通配符子域的子目录,而不在地址栏URL改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!