[英]Htaccess - get last word of url
I want to implement a .htaccess redirect based on the following pattern: 我想基于以下模式实现.htaccess重定向:
www.site.com/ugly-depreciated-values-name
to 至
www.site.com/location/name
import re
x="www.site.com/ugly-depreciated-values-name"
print re.sub(r"(.*?/).*?-(\w+)$",r"\1location/\2",x)
Output:www.site.com/location/name 输出:www.site.com/location/name
This is in Python. 这是在Python中。
You can use this rule in your root .htaccess: 您可以在根.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.