使用Apache VHOST配置有选择地重定向到新域



这是使用Apache Vhost配置

重定向到新域的后续问题

我想要我的请求

某种程度上:

要重定向到

womerotherdomain.com/dell-inspiron-15

,但对于某些被列入白名单的产品有选择性。

例如,产品:

  1. dell-inspiron-15。
  2. dell-inspiron-16。
  3. dell-inspiron-17

重定向到新URL,但对于任何其他产品,我都想使用当前路径本身。

当前我的VHOST配置如下所示。它将查询参数中的所有产品重定向到某些产品。

Listen 12567
NameVirtualHost *:12567
<VirtualHost *:12567>
    ServerName somedomain.com
    ProxyPreserveHost On
    RewriteEngine On
    RewriteCond %{QUERY_STRING} (?:^|&)product=([^&]+) [NC]
    RewriteRule ^/?loadproduct$ http://someotherdomain.com/%1? [R=301,L,NC]
</VirtualHost>

问题:

  1. 如上所述,如何有选择地重定向?
  2. 鉴于我的白名单产品清单很小(也许是10-11个项目),什么是存储这种白色产品并在Vhost中阅读的理想场所,以及如何。

这里的任何线索都非常感谢。

由于您有少量型号,因此您可以将它们列出,例如:

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]

默认情况下,用每条线之间的操作解释了重新值。因此,在触发重写之前,每个条件都必须为真。在这里,在行之间使用或操作员。只要一个匹配,您就可以了。

最新更新