请帮忙。应该对那些了解和理解的人来说很简单。我只需要.htaccess重写规则在一次重定向操作中将所有下划线替换为破折号。我把
RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301]
但是它逐个替换,如果URL有五个下划线,则会强制重定向5个!是否有可能,在相同的重写规则(用_替换_)搜索字符串并替换它?例如:
host.com/i_want_it_to_be_replaced.html ->
host.com/i-want-it-to-be-replaced.html
并且,如果它看到“i_want”或“i-want”,则用“force”替换它:
host.com/i_want_it_to_be_replaced.html ->
host.com/force-it-to-be-replaced.html
谢谢!
答案 0 :(得分:0)
尝试:
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule !_ %{REQUEST_URI} [R=301,L]
RewriteRule (.*)i[_-]want(.*) /$1force$2 [L]
RewriteRule ^(.*)_(.*)$ /$1-$2 [L]