当前位置:Gxlcms > PHP教程 > URL重写根据域名显示不同内容

URL重写根据域名显示不同内容

时间:2021-07-01 10:21:17 帮助过:18人阅读

目前apache伪静态URL重写.htaccess里是下面规则:
http://www.abc.com ---> index.php
http://www.abc.com/late/ ---> ./filedir/late.php?p=1
http://www.abc.com/popular/ ---> ./filedir/popular.php?p=1
http://www.abc.com/down/name-id/ ---> ./filedir/detail.php?id=number
http://www.abc.com/cat/catname-catid/ ---> ./filedir/cat.php?catid=number

http://www.abc.com/bb ---> ./filedir/bb.php
http://www.abc.com/bblate/ ---> ./filedir/bblate.php?p=1
http://www.abc.com/bbpopular/ ---> ./filedir/bbpopular.php?p=1
http://www.abc.com/bdown/name-id/ ---> ./filedir/bbdetail.php?id=number
http://www.abc.com/bcat/bcatname-catid/ ---> ./filedir/bbcat.php?bbcat.php?catid=number

现要增加一个二级域名bb.abc.com也指向www.abc.com服务器,并将域名后路径改为和www.abc.com形式相同,即
http://bb.abc.com ---> ./filedir/bb.php
http://bb.abc.com/late/ ---> ./filedir/bblate.php?p=1
http://bb.abc.com/popular/ ---> ./filedir/bbpopular.php?p=1
http://bb.abc.com/down/name-id/ ---> ./filedir/bbdetail.php?id=number
http://bb.abc.com/cat/bcatname-catid/ ---> ./filedir/bbcat.php?bbcat.php?catid=number

这要如何写.htaccess的URL重写规则呢?根据判断域名显示不同内容

回复内容:

目前apache伪静态URL重写.htaccess里是下面规则:
http://www.abc.com ---> index.php
http://www.abc.com/late/ ---> ./filedir/late.php?p=1
http://www.abc.com/popular/ ---> ./filedir/popular.php?p=1
http://www.abc.com/down/name-id/ ---> ./filedir/detail.php?id=number
http://www.abc.com/cat/catname-catid/ ---> ./filedir/cat.php?catid=number

http://www.abc.com/bb ---> ./filedir/bb.php
http://www.abc.com/bblate/ ---> ./filedir/bblate.php?p=1
http://www.abc.com/bbpopular/ ---> ./filedir/bbpopular.php?p=1
http://www.abc.com/bdown/name-id/ ---> ./filedir/bbdetail.php?id=number
http://www.abc.com/bcat/bcatname-catid/ ---> ./filedir/bbcat.php?bbcat.php?catid=number

现要增加一个二级域名bb.abc.com也指向www.abc.com服务器,并将域名后路径改为和www.abc.com形式相同,即
http://bb.abc.com ---> ./filedir/bb.php
http://bb.abc.com/late/ ---> ./filedir/bblate.php?p=1
http://bb.abc.com/popular/ ---> ./filedir/bbpopular.php?p=1
http://bb.abc.com/down/name-id/ ---> ./filedir/bbdetail.php?id=number
http://bb.abc.com/cat/bcatname-catid/ ---> ./filedir/bbcat.php?bbcat.php?catid=number

这要如何写.htaccess的URL重写规则呢?根据判断域名显示不同内容

找到方法:
RewriteCond %{http_host} ^bb.abc.com$
RewriteRule ^(/)?$ ./filedir/bb.php [L]
RewriteCond %{http_host} ^bb.abc.com$
RewriteRule ^late/$ ./filedir/bblate.php?p=1 [L]

同样谢谢 nathan_wu

serveralias bb.abc.com

人气教程排行