htaccess url rewriting
Is there an easy way to 301 redirect
http://www.si开发者_运维技巧te-name.com/yellow-cars
to
http://www.site-name.com/shop/catalog/all/Yellow_Cars
I'm not sure if the last segment in the URL can be created in the .htaccess file?
You can try with something like:
RewriteMap capitalize int:toupper RewriteRule /(\w)(\w+)-(\w)(\w+) /shop/catalog/all/${capitalize:$1}$2_${capitalize:$3}$4 [R=301]
It can be done with RewriteMap
:
dehyphen.py
#!/usr/bin/python
import sys
for line in sys.stdin:
print '_'.join(s.capitalize() for s in line.split('-'))
sys.stdout.flush()
httpd conf:
RewriteMap dehyphen prg:dehyphen.py
RewriteRule /(.+) /shop/catalog/all/${dehyphen:$1} [L]
Make sure that dehyphen.py is made executable.
精彩评论