将下划线重定向到破折号

时间:2013-07-04 18:53:20

标签: redirect mod-rewrite

我想.htaccess重定向:

http://www.site.com/projects/datasheets/batteries_data.php?file=abcd
http://www.site.com/projects/datasheets/charge_control_data.php?file=abcd
......

http://www.site.com/projects/datasheets/batteries-data.php?file=abcd
http://www.site.com/projects/datasheets/charge-ontrol-data.php?file=abcd
......

我尝试过几种方法:

RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)$ /$1-$2-$3-$4-$5-$6-$7-$8-$9 [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)$ /$1-$2-$3-$4-$5-$6-$7-$8 [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)$ /$1-$2-$3-$4-$5-$6-$7 [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)$ /$1-$2-$3-$4-$5-$6 [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)$ /$1-$2-$3-$4-$5 [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)$ /$1-$2-$3-$4 [R=301,L]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)$ /$1-$2-$3 [R=301,L]
RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,R=301]

但它不起作用

1 个答案:

答案 0 :(得分:0)

谢谢Prix,它有效。问题是我不知道我必须把它放在所有其他重写规则之前。