嘿,我正试图创建一个重定向映射,但我试图重定向的链接已生成,重要的是末尾的ID号。我想知道如何基于跳过最后一个连字符"前面的所有内容来重定向-"在url中。
我试图重定向的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>
关于如何在字符串中搜索精确ID匹配的答案:
RewriteRule ^/discover/en/suppliers/(.*)([0-9]{6}) /manufacturer/${discover:$2}/ [R=301]