如何使用htaccess用短划线替换下划线?

时间:2012-01-11 16:51:53

标签: regex apache .htaccess mod-rewrite

好的,这是我的网址:

http://example.com/home/process_login

我想用破折号替换下划线。

因此http://example.com/home/process-login将转到上面的网址,但它仍会在网址栏中显示process-login

希望这是有道理的。我发现的唯一解决方案是重定向,我不想重定向。我希望它能像我概述的那样阅读。

1 个答案:

答案 0 :(得分:2)

使用此代码:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteRule ^(home/)(.*)-(.*)$ $1$2_$3 [L,NC]

更新:根据您的评论

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{REQUEST_URI} !^/?(coremeasures/index\.php/|index\.php|home/|images/|robots\.txt)
RewriteRule ^(.*)$ /coremeasures/index.php/$1 [L]
RewriteRule ^(home/)(.*)-(.*)$ $1$2_$3 [L,NC]

更新2:根据您的评论

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteRule ^(?!(coremeasures/index\.php/|index\.php|home/|images/|robots\.txt))(.*)$ coremeasures/index.php/$1 [L]
RewriteRule ^(home/)(.*)-(.*)$ $1$2_$3 [L,NC]