使用 apache vhost 配置有选择地重定向到新域
Selectively redirect to a new domain using apache vhost configuration
这是关于
的后续问题
我想要来自
的请求
somedomain.com/loadproduct?product=dell-inspiron-15
将重定向到
其他域。com/dell-inspiron-15
但有选择地针对某些列入白名单的产品。
例如产品:
- dell-inspiron-15.
- dell-inspiron-16.
- 戴尔灵越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 中读取的理想位置以及如何读取。
非常感谢这里的任何线索。
由于您的模型数量较少,您可以将它们列出来,如下所示:
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。这里在行之间使用 OR 运算符。只要匹配一个就行了。
这是关于
我想要来自
的请求somedomain.com/loadproduct?product=dell-inspiron-15
将重定向到
其他域。com/dell-inspiron-15
但有选择地针对某些列入白名单的产品。
例如产品:
- dell-inspiron-15.
- dell-inspiron-16.
- 戴尔灵越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 中读取的理想位置以及如何读取。
非常感谢这里的任何线索。
由于您的模型数量较少,您可以将它们列出来,如下所示:
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。这里在行之间使用 OR 运算符。只要匹配一个就行了。