重写规则为在一个单一的应用程序处理多个域? [英] RewriteRule for handling multiple domains within one single app?
问题描述
说我有一个应用在 example.com
一个客户 migth有它的含量 example.com/customer/hisname /
。
嗯,我想成为可能,客户的的受让人的作为自己的内容领域,比如 hisname.com
,所以这(hisdomain.com)呈现 example.com/customer/hisname /
。
要做到这一点,我创建了两个虚拟主机,均具有在同一个地方的根目录下,我已经为了过滤HTTP_HOST书面.htaccess文件,如果没有example.com然后重写的方式,它传递给example.com/customer/hisname~~V /.
不过,这种方法是行不通的,而我没有得到/客户/ hisname /部分URI。 如果我走在example.com/index.php到hisname.com/list/~~V,在这里我需要有两个/表/和(为preFIX)/客户/ hisname /,我只得到,如你可能会想到刚/列表/. P>
那么,什么是正确的做法对吗?
如果您可以创建虚拟主机的,你应该使用设置正确的文档根目录,而不是的mod_rewrite 一>
<虚拟主机w.x.y.z:80>
的ServerAdmin webmaster@hisname.com
DocumentRoot的/路径/要/网络/客户/ hisname
服务器名hisname.com
...
< /虚拟主机>
如果无法做到这一点,你可以提取主机
部分,做一个内部重写
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{HTTP_HOST}!^(?WWW \)?例如\ .COM $
的RewriteCond%{HTTP_HOST} ^(。+)\。com $
重写规则^ /index.php?$p$pfix=customer/%1&request=%{REQUEST_URI} [L,QSA]
Say I have an app at example.com.
One customer migth have it's content in example.com/customer/hisname/
.
Well, I would like to make possible that the customer assigns a domain for his content, say hisname.com
, so this (hisdomain.com) renders example.com/customer/hisname/
.
To do that I have created two virtual hosts, both having the root directory in the same place, and I have written a .htaccess file in order to filter the http_host and if not example.com then rewrite in such manner that it passes the request to example.com/customer/hisname/.
Still, this approach doesn't work while I do not get the /customer/hisname/ part in URI. If I go to hisname.com/list/ in the example.com/index.php, where I would need to have both /list/ and (as a prefix) /customer/hisname/, I only get, as you might expect just /list/.
So, what would be the right approach for this?
If you can create Virtual Hosts, you should set the proper document root instead of using mod_rewrite
<VirtualHost w.x.y.z:80>
ServerAdmin webmaster@hisname.com
DocumentRoot /path/to/www/customer/hisname
ServerName hisname.com
...
</VirtualHost>
If this is not possible, you can extract the host
part and do an internal rewrite
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^(?www\.)?example\.com$
RewriteCond %{HTTP_HOST} ^(.+)\.com$
RewriteRule ^ /index.php?prefix=customer/%1&request=%{REQUEST_URI} [L,QSA]
这篇关于重写规则为在一个单一的应用程序处理多个域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!