开发者

htaccess url rewriting

开发者 https://www.devze.com 2022-12-17 23:46 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消