【发布时间】:2018-05-12 20:17:20
【问题描述】:
这是Redirect to a new domain using apache vhost configuration的后续问题
我想要来自
的请求somedomain.com/loadproduct?product=dell-inspiron-15
被重定向到
someotherdomain.com/dell-inspiron-15
但选择性地针对某些列入白名单的产品。
例如产品:
- dell-inspiron-15。
- dell-inspiron-16。
- dell-inspiron-17
重定向到新的 URL,但对于我想使用当前路径本身的任何其他产品。
目前我的虚拟主机配置如下所示。它为查询参数中的所有产品重定向到某个其他域。
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>
问题:
- 如上所述,如何选择性地重定向?
- 鉴于我列入白名单的产品列表很小(可能有 10 到 11 项),存储这些列入白名单的产品并在 vhost 中阅读以及如何阅读的理想场所是什么。
非常感谢这里的任何线索。
【问题讨论】:
-
如果列表像您说的那么小,请直接在您的 VirtualHost 中配置它们。当 10-15 RewriteCond 会为您提供所需的内容并继续进行项目中的其他事情时,尝试做一些复杂的事情是没有用的。
-
你能举个例子吗?
-
我会给出一个答案,cmments中的代码很糟糕。
标签: apache mod-rewrite httpd.conf vhosts