Apache仅重定向特定网址

时间:2018-04-11 15:18:19

标签: apache proxy http-redirect

我正在设置一个具有一个代理和两个后端服务器的测试环境。

我想像这样重定向:

example.com/app1/ -> apache_1
example.com/app2/ -> apache_2
example.com and all the rest to apache_1

我已经使用此配置进行了前两次重定向:

<Location /app1/>
    ProxyPass http://apache_1/
    ProxyPassReverse http://apache_1/
    Order allow,deny
    Allow from all
</Location>

<Location /app2/>
    ProxyPass http://apache_2/
    ProxyPassReverse http://apache_2/
    Order allow,deny
    Allow from all
</Location>

现在我要添加类似的内容:

<Location 'everything else'>
    ProxyPass http://apache_1/
    ProxyPassReverse http://apache_1/
    Order allow,deny
    Allow from all
</Location>

如果我使用Location / apache将所有内容重定向到apache_1,并且在localhost / app1 /和/ app2 /

上找不到显示404的内容

这可以用apache吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

如果您更清楚一点,但是如果exam​​ple.com上没有其他内容,那就太好了,那么我能想到的最佳解决方案是ErrorDocument 404 /file

在文件中,您可以使用HTML <meta>标签:

<meta http-equiv="refresh" content="0; url=your-url" />

content属性中,0表示页面将在0秒后刷新,并重定向到url。

或者您可以包含php header

header("Location: url");