如何使用url重写,更改url
http://www.mydomain.com/this-is-a-new-article
至
http://www.mydomain.com/this_is_a_new_article ?
使用:
# RewriteRule ^(.+?)-(.+?)$ (.+?)_(.+?) [R=301,L,NE] ?
sedhyphen.sh:
#!/bin/sh sed -u 's/-/_/g'
httpd conf:
RewriteMap sed-hyphen prg:sedhyphen.sh RewriteRule ^(.*)$ ${sed-hyphen:$1} [L]
确保将sedhyphen.sh设置为可执行文件。
采取从 – https://stackoverflow.com/questions/2105009/mod-rewrite-replace-all-underscore-with-hyphen (他们正在转换相反的方式)
你也可以做这样的事情,但它不那么活跃
(。 ) – (。 )/ $ RewriteRule(。 ) – (。 ) – (。 )/ http://website.com $ 1_ $ 2_ $ 3 / [R = 301] RewriteCond%{REQUEST_URI} ^
来自:http: //yoast.com/apache-rewrite-dash-underscore/