有人可以帮我这个忙吗?谢谢解决方案您可以使用以下两个递归规则用连字符代替所有下划线,而不是使用许多复杂的规则:RewriteEngine OnRewriteRule \.(html?|php)$ - [L,NC]RewriteRule ^([^_]*)_+([^_]*)$ http://www.askapache.com/$1-$2 [L,R=301,NE]RewriteRule ^([^_]*)_+(.*)$ $1-$2 [N,DPI]I am trying to change all underscores to hyphens for my website. currently I have this code added to .htaccess file. RewriteBase /RewriteRule !\.(html|php)$ - [S=6]RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6-$7 [E=underscores:Yes]RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6 [E=underscores:Yes]RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=underscores:Yes]RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=underscores:Yes]RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=underscores:Yes]RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=underscores:Yes]RewriteCond %{ENV:underscores} ^Yes$RewriteRule (.*) http://www.askapache.com/$1 [R=301,L]However, It only works for url such as www.abc.com/about_us to www.abc.com/about-us and not for urls that have more than two words such as www.abc.com/about_us_what_do_you_meanCan somebody help me out regarding this. Thanks 解决方案 Rather than so many complex rules, you can use these two recursive rules to replace all underscore by hyphens:RewriteEngine OnRewriteRule \.(html?|php)$ - [L,NC]RewriteRule ^([^_]*)_+([^_]*)$ http://www.askapache.com/$1-$2 [L,R=301,NE]RewriteRule ^([^_]*)_+(.*)$ $1-$2 [N,DPI] 这篇关于htaccess文件-url中两个以上单词的下划线改为连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-11 04:59