>  기사  >  백엔드 개발  >  URL重写 根据域名显示不同内容

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

WBOY
WBOY원래의
2016-06-06 20:37:411679검색

目前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重写规则呢?根据判断域名显示不同内容

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重写规则呢?根据判断域名显示不同内容

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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.