【问题标题】:Apache multiple URL to one domain redirectApache 多个 URL 到一个域重定向
【发布时间】:2011-02-18 00:42:32
【问题描述】:

最近两天,我花了很多时间来解决我的问题,也许有人可以帮助我。

问题:我需要将不同的 url 重定向到一个用于工件的 tomcat webbase-dir。 以下网址应指向 tomcat/artifactory webapp:

maven-repo.example.local ; maven-repo.example.local/artifactory ; srv-example/artifactory

其中 maven-repo.example.local 是服务器主机名的 dns:“srv-example” 我正在通过 JK_mod 模块访问 tomcat 应用程序。 webapp在ROOT目录下 这是我到目前为止所得到的:

<VirtualHost *:80>
   #If URL contains "artifactory" strip down and redirect
   RewriteEngine on
   RewriteCond %{HTTP_HOST} ^\artifactory\$ [NC] 
   # (how can I remove 'artifactory' from the redirected parameters? )
   RewriteRule ^(.*)$ http://maven-repo.example.local/$1 [R=301,L] 

   ServerName localhost
   ErrorLog "logs/redirect-error_log"       
</VirtualHost>

<VirtualHost *:80>
    ServerName maven-repo.example.local
    ErrorLog "logs/maven-repo.example.local-error.log"
    CustomLog "logs/maven-repo.example.local-access.log" common   
    #calling tomcat webapp in ROOT
    JkMount /* ajp13w
</VirtualHost>

webapp 正在使用“maven-repo.example.local”,但使用“maven-repo.example.local/artifactory”时,tomcat 会给出 404 -“请求的资源 () 不可用。” 似乎 mod_rewrite 没有任何效果,即使我重定向到另一个页面,例如 google.com

我正在 Windows 7 上测试,在“system32/drivers/hosts”文件中添加了 maven-repo.example.local

提前致谢!

【问题讨论】:

    标签: apache url tomcat redirect virtualhost


    【解决方案1】:

    非常感谢您的提示@PHP-Prabhu

    一个简单的:

    RedirectPermanent /artifactory /.
    

    在 apache httpd.conf 中成功了!

    【讨论】:

      【解决方案2】:

      首先,在处理别名之前处理所有重定向,因此与重定向或 RedirectMatch 匹配的请求将永远不会应用别名。其次,别名和重定向按照它们在配置文件中出现的顺序进行处理,第一个匹配优先

      请查看此网址

      http://httpd.apache.org/docs/2.1/mod/mod_alias.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-12
        • 1970-01-01
        • 2018-10-27
        • 1970-01-01
        • 2020-10-01
        相关资源
        最近更新 更多