RewriteRule for handling multiple domains within one single app?

試著忘記壹切 提交于 2019-12-08 19:59:19

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]

use the variable $_SERVER['HTTP_HOST'] and load a different view depending on the host requested. Make sure you handle all subhosts needed and have a default page as well

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!