1

how to use url rewrite, change url from

http://www.mydomain.com/this-is-a-new-article

to

http://www.mydomain.com/this_is_a_new_article?

Use:

# RewriteRule ^(.+?)-(.+?)$ (.+?)_(.+?) [R=301,L,NE] ?

1 Answer 1

3

sedhyphen.sh:

#!/bin/sh
sed -u 's/-/_/g'

httpd conf:

RewriteMap sed-hyphen prg:sedhyphen.sh
RewriteRule ^(.*)$ ${sed-hyphen:$1} [L]

Make sure that sedhyphen.sh is set executable.

Taken from - https://stackoverflow.com/questions/2105009/mod-rewrite-replace-all-underscore-with-hyphen (They were converting the opposite way)

You could also do something like this but it is less dynamic

RewriteCond %{REQUEST_URI} ^(.)-(.)-(.)/$ RewriteRule (.)-(.)-(.)/ http://website.com$1_$2_$3/ [R=301]

From: http://yoast.com/apache-rewrite-dash-underscore/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .