【发布时间】:2014-09-17 15:01:09
【问题描述】:
我正在转发这样的子域(将 sub.example.com 转换为 example.com/subdomain/sub)
# the rewrite that forwards sub-domains as guide
RewriteCond %{HTTP_HOST} ^(.+?)\.(.*) [NC]
RewriteRule (.*) http://%{SERVER_NAME}:9081/subdomain/%1/$1 [P,QSA,NE]
这很好用,但是会破坏所有指向 CSS/JS 文件的相关链接。
我希望我可以加入另一条规则,无论子域如何,它都会停止转发任何 example.com/resources 请求,即
RewriteRule ^resources\/$ http://%{SERVER_NAME}:9081/resources/$1 [QSA,P,L]
当前正在转发到 example.com/subdomain/resources,当我希望它转发到 example.com/resources 时。
知道如何覆盖特定子文件夹上子域的重写规则,或者这不可能吗?其他解决方案是我希望避免的 CSS/JS 中的绝对 URL。
谢谢
【问题讨论】:
-
通常您会为此使用 mod_proxy 的
ProxyPass和ProxyPassReverse。然而,成功将取决于被代理的应用程序(无论您使用 mod_proxy 还是 mod_rewrite)。两种方式都不会编辑响应正文,只会编辑标题。
标签: apache .htaccess mod-rewrite