【发布时间】:2014-09-14 20:28:42
【问题描述】:
尝试进行重写,以便有人会像这样的网址:
a-b.domain.com 实际查看 domain.com/a/b
可能只需要重写吗?
【问题讨论】:
标签: apache rewrite subdomain subdirectory
尝试进行重写,以便有人会像这样的网址:
a-b.domain.com 实际查看 domain.com/a/b
可能只需要重写吗?
【问题讨论】:
标签: apache rewrite subdomain subdirectory
是的,这是可能的。您可以参考我很久以前准备的以下代码。
RewriteEngine On -- This will enable rewrite module
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^(.*).abc\.domain\.com/([^/]*) [NC] -- This will check Hostname & URI where first (.*) = %1 & second (.*) = %2 variable as we needed dynamic variables so we greped it.
RewriteCond %1<->%2 !^(.*)<->\1$ [NC] -- This will check if condition %1 is not equal to %2 than proceed to rewrite to the rule mentioned below.
RewriteRule ^(.*) http://domain.com:9090/%1$1 [QSA,P] -- This will append %1 in URL so with help of proxy settings it will grab the content from tomcat @ port 9090 with directory name %1 and keep the query string as it is with help of "QSA" string.
RewriteCond %1<->%2 ^(.*)<->\1$ [NC] -- This will check if condition %1 is equal to %2 than proceed to rewrite to the rule mentioned below.
RewriteRule ^(.*) http://domain.com:9090$1 [QSA,P] -- This will not append %1 in URL so with help of proxy settings it will grab the content from tomcat @ port 9090 with directory name %1 and keep the query string as it is with help of "QSA" string.
【讨论】: