【问题标题】:Apache Rule Rewrite Map Regular ExpressionApache Rule Rewrite Map 正则表达式
【发布时间】:2021-03-16 18:32:05
【问题描述】:

嘿,我正在尝试创建重定向映射,但我尝试重定向的链接已生成,最后的 ID 号才是最重要的。 我想知道如何根据跳过网址中最后一个连字符“-”前面的所有内容来重定向。

我尝试重定向的 URL:

    http://staging.mysite.com/discover/en/suppliers/TD-Machi-LC-363868
    but can be any possible combination:
    http://staging.mysite.com/discover/en/suppliers/TD-Machining-101-LCC-363868
    http://staging.mysite.com/discover/en/suppliers/Ted-Baker-D-363868
    http://staging.mysite.com/discover/en/suppliers/363868

我目前试图开始工作的重定向是:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteMap discovertxt txt:/opt/bitnami/apps/wordpress/htdocs/maps/discover_all_map.txt
    RewriteMap discoverdestinationtxt txt:/opt/bitnami/apps/wordpress/htdocs/maps/discover_destination_map.txt
    RewriteMap discoversourcetxt txt:/opt/bitnami/apps/wordpress/htdocs/maps/discover_source_map.txt
    # Discover Redirect
    # RewriteCond ${discoverdestinationtxt:$1} >${discoversourcetxt:$1} [NC]
    
    # Trying to capture only the last value of the string
    RewriteRule ^/discover/en/suppliers/^(.*)-(.*)-(.*)-(.*) /manufacturer/${discovertxt:$4}/ [R=301,L]
    
    # Bellow method works only if ID alone is supplied.
    # RewriteRule ^/discover/en/suppliers/(.*) /manufacturer/${discovertxt:$1}/ [R=301,L]
    
    </IfModule>

【问题讨论】:

    标签: regex apache mod-rewrite


    【解决方案1】:

    关于如何在字符串中搜索完全匹配的 ID 的答案:

        RewriteRule ^/discover/en/suppliers/(.*)([0-9]{6}) /manufacturer/${discover:$2}/ [R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-02
      • 1970-01-01
      • 2011-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多