如何使用Htaccess规则用连字符替换下划线

时间:2014-03-31 06:29:31

标签: php .htaccess replace url-rewriting

如何使用Htaccess规则

用连字符替换下划线

这是链接:

http://iloansdirect.netsmartz.us/property_finder.shtml

我想在下面链接:

http://iloansdirect.netsmartz.us/property-finder.shtml

2 个答案:

答案 0 :(得分:0)

在htaccess文件中尝试以下代码:

RewriteEngine On
RewriteRule ^(.*)_(.*)$ /$1-$2 [L,R=301]

答案 1 :(得分:0)

您可以查看以下内容

Options +FollowSymLinks
RewriteEngine On
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]

发现于http://www.askapache.com/htaccess/rewrite-underscores-hyphens-seo-url.html