后备

编程入门 行业动态 更新时间:2024-10-04 17:32:11
本文介绍了后备-使用apache vhost配置重定向到新域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是 stackoverflow/posts/47547418

我想要

somedomain/loadproduct?product=dell-inspiron-15

有选择地重定向到

someotherdomain/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/old/loadproduct?product=dell-inspiron-15

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

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

但如果他们使用

somedomain/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 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$ someotherdomain/%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$ someotherdomain/%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.

更多推荐

后备

本文发布于:2023-11-02 06:46:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551657.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!