[英]Htaccess - get last word of url
我想基於以下模式實現.htaccess重定向:
www.site.com/ugly-depreciated-values-name
至
www.site.com/location/name
import re
x="www.site.com/ugly-depreciated-values-name"
print re.sub(r"(.*?/).*?-(\w+)$",r"\1location/\2",x)
輸出:www.site.com/location/name
這是在Python中。
您可以在根.htaccess中使用此規則:
RewriteEngine On
RewriteRule ^.+?-([^/-]+)/?$ /$1 [L,R=302]
RewriteEngine On
RewriteRule ^[A-Z0-9a-z\-]+-(.*)$ http://www.example.com/location/$1 [R=301,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.