【问题标题】:Apache Rewrite a-b.domain.com to domain.com/a/b?Apache 将 a-b.domain.com 重写为 domain.com/a/b?
【发布时间】:2014-09-14 20:28:42
【问题描述】:

尝试进行重写,以便有人会像这样的网址:

a-b.domain.com 实际查看 domain.com/a/b

可能只需要重写吗?

【问题讨论】:

    标签: apache rewrite subdomain subdirectory


    【解决方案1】:

    是的,这是可能的。您可以参考我很久以前准备的以下代码。

    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-06
      • 1970-01-01
      • 2011-06-21
      • 2012-11-12
      • 1970-01-01
      • 2014-03-29
      • 1970-01-01
      • 2015-01-19
      相关资源
      最近更新 更多