tags:

views:

33

answers:

2

Is there an easy way to 301 redirect

http://www.site-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?

+1  A: 

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]
Lorenzo V.
A: 

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.

Ignacio Vazquez-Abrams