首页  >  问答  >  正文

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

高洛峰高洛峰2724 天前512

全部回复(2)我来回复

  • 高洛峰

    高洛峰2017-04-10 15:25:46

    找到方法:
    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

    回复
    0
  • 天蓬老师

    天蓬老师2017-04-10 15:25:46

    serveralias bb.abc.com

    回复
    0
  • 取消回复