后备-使用apache vhost配置重定向到新域 [英] Fallback - redirect to a new domain using apache vhost configuration

查看:166
本文介绍了后备-使用apache vhost配置重定向到新域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 https://stackoverflow.com/posts/47547418

我想要

somedomain.com/loadproduct?product=dell-inspiron-15

有选择地重定向到

someotherdomain.com/dell-inspiron-15

,但同时我想确保新域是否出了问题,用户仍然可以通过在URL中添加/old来使用旧域.

but at the same time I want to make sure if something goes wrong with the new domain, users are still able to use old domain by adding /old in the url.

例如,如果用户使用

somedomain.com/old/loadproduct?product=dell-inspiron-15

那么它们不应被重定向到 someotherdomain ,而应通过有效的URL somedomain.com/loadproduct?product=dell-inspiron-15

then they should not be redirected to someotherdomain but should be served through a valid url somedomain.com/loadproduct?product=dell-inspiron-15

但如果他们使用

somedomain.com/loadproduct?product=dell-inspiron-15

它们应该被重定向.

当前,我的虚拟主机配置如下所示.它将重定向到选定产品的某个其他域,但没有后备配置.

Currently my vhost configuration looks like below. It redirects to someotherdomain for selected products but there is no fallback configuration.

Listen 12567
NameVirtualHost *:12567

<VirtualHost *:12567>
    ServerName somedomain.com
    ProxyPreserveHost On

    RewriteEngine On
    RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-15) [NC,OR]
    RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-16) [NC,OR]
    RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-17) [NC]
    RewriteRule ^/?loadproduct$ http://someotherdomain.com/%1? [R=301,L,NC]
</VirtualHost>

这里的任何潜在顾客都非常感激.

Any leads here is really appreciated.

推荐答案

修改您的RewriteCond条件,并在其表示不接受/old/的路径(URI)中添加一个条件.所以:

Modify your RewriteCond conditions and add one where it says not to accept /old/ in the path (URI). So:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^.*/old/.*$ [NC]
RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-15) [NC,OR]
RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-16) [NC,OR]
RewriteCond %{QUERY_STRING} (?:^|&)product=(Dell-Inspiron-17) [NC]
RewriteRule ^/?loadproduct$ http://someotherdomain.com/%1? [R=301,L,NC]

在第一行中,无需指定[AND],因为它是隐式的. !字符使匹配无效.

In the first line, no need to specify [AND], as it is implicit. The ! character negates the match.

免责声明:我尚未在真正的Apache上进行过测试,但是我敢肯定这是可以的.

Disclaimer: I have not tested this on a real Apache, but I am pretty sure it is ok.

这篇关于后备-使用apache vhost配置重定向到新域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆