使用apache vhost配置选择性地重定向到新域 [英] Selectively redirect to a new domain using apache vhost configuration

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

问题描述

这是关于>重定向到新域的后续问题使用apache vhost配置

我希望我的请求

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

要重定向到

someotherdomain.com/dell-inspiron-15

,但有选择地针对列入白名单的某些产品.

but selectively for some products which are whitelisted.

例如产品:

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

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

redirect to the new URL but for any other products I want to use the current path itself.

当前,我的虚拟主机配置如下所示.对于查询参数中的所有产品,它将重定向到某个其他域.

Currently my vhost configuration looks like below. It redirects to someotherdomain for all the products in query parameter.

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中读取内容以及如何阅读的理想场所.

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

Any leads here is really appreciated.

推荐答案

由于模型数量较少,因此可以将它们列出来,如下所示:

Since you have a small number of models, you could just list them out, like so:

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]

默认情况下,RewriteCond行通过每行之间的AND操作进行解释.因此,在触发RewriteRule之前,每个条件都必须为TRUE.这里在两行之间使用或"运算符.只要一场比赛,你就可以.

By default, RewriteCond lines are interpreted with the AND operation between each. So each condition must be TRUE before the RewriteRule is triggered. Here use the OR operator between the lines. As long as one matches, you are ok.

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

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