I want to implement a .htaccess redirect based on the following pattern:
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
This is in Python.
You can use this rule in your root .htaccess:
RewriteEngine On
RewriteRule ^.+?-([^/-]+)/?$ /$1 [L,R=302]
RewriteEngine On
RewriteRule ^[A-Z0-9a-z\-]+-(.*)$ http://www.example.com/location/$1 [R=301,L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.