2017-08-16 43 views
1

在htaccess中使用apache我只想在它后面有下划线时替换url中的所有句点。Apache将两个连接的字符替换为url中的一个

我想example.com?index.php/blog/low_vs._high重定向到 example.com?index.php/blog/low_vs_high

有人能告诉我如何做到这一点? 这里是我有什么,不知道从哪里走,或如何正确调试。谢谢。

RewriteEngine on 
RewriteCond %{REQUEST_URI} ^/(.*)\._(.*)$ 
RewriteRule ^(.*)\.(.*)$ /$1$2 [L,R=301] 

回答

1

您可以使用此规则:

# execute when there are multiple occurrences of ._ 
RewriteCond %{REQUEST_URI} ^/(.*)\.(_.*\._.*)$ 
RewriteRule^/%1%2 [L] 

# execute when there is only one occurrence of ._ 
RewriteCond %{REQUEST_URI} ^/(.*)\.(_.*)$ 
RewriteRule^/%1%2 [L,NE,R=301] 
+0

将它在全球更换?或一次? – Dekel

+0

检查我的更新规则。之前的版本也在全球范围内进行替换,但执行了多个重定向更新后的版本将全球取代,但客户端将看到单一重定向以获得更好和更快的体验。 – anubhava

相关问题