Thursday, July 3, 2008

Apache Rewrite for underscore to hyphen

I have faced an url issue in my webapplication.

I was asked to rewrite the requests for the html pages which has "_" ,

Example :


the following rule will work fine for the above scenario,

RewriteRule ^/([^_]+)_([^_]+)_([^_]+)$ /$1-$2-$3 [L,R=301] #pages with 2 underscores
RewriteRule ^/([^_]+)_([^_]+)$ /$1-$2 [L,R=301] #pages with 1 underscore


No comments: