使用apache vhost配置选择性地重定向到新域

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

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

我希望我的请求

somedomain/loadproduct?product=dell-inspiron-15

要重定向到

someotherdomain/dell-inspiron-15

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

but selectively for some products which are whitelisted.

例如产品:

  • dell-inspiron-15.
  • dell-inspiron-16.
  • 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 ProxyPreserveHost On RewriteEngine On RewriteCond %{QUERY_STRING} (?:^|&)product=([^&]+) [NC] RewriteRule ^/?loadproduct$ someotherdomain/%1? [R=301,L,NC] </VirtualHost>

    问题:

  • 如上所述,如何选择重定向?
  • 考虑到我列入白名单的产品列表很小(也许有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$ someotherdomain/%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配置选择性地重定向到新域

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

    发布评论

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

    >www.elefans.com

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