【发布时间】:2017-05-12 09:24:00
【问题描述】:
我正在使用 htaccess mod-rewrite 将子域 url 重定向到带有参数的域 url,例如:
subdomain.example.com is redirect to example.com?id=subdomain
subdomain.example.com/page is redirect to example.com/page/?id=subdomain
subdomain.example.com/page1/page2 is redirect to example.com/page1/page2/?id=subdomain
subdomain.example.com/page1/page2?pol=abc is redirect to example.com/page1/page2/?id=subdomain&pol=abc
我在 htaccess 中使用此代码:
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com
RewriteRule ^([^/]*)$ http://example.com/$1?id=%1 [R,L]
为此域启用了通配符。
当 url 是 subdomain.domain.com 时这很好用,但是当 url 是目录重定向时不起作用。例如,当我在网络浏览器中写地址 subdomain.example.com/page 时,我得到了相同的地址。
【问题讨论】: