如何解决Apache Rule Rewrite Map 正则表达式
嘿,我正在尝试创建一个重定向映射,但我尝试重定向的链接已生成,只有末尾的 ID 号才是重要的。 我想知道如何根据跳过网址中最后一个连字符“-”前的所有内容进行重定向。
我试图重定向的网址:
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>
解决方法
如何在字符串中搜索完全匹配的 ID 的答案:
RewriteRule ^/discover/en/suppliers/(.*)([0-9]{6}) /manufacturer/${discover:$2}/ [R=301]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。