.htaccess重写规则,在url中使用字符串替换

时间:2016-09-24 17:06:54

标签: .htaccess mod-rewrite url-rewriting url-redirection

我想重定向在网址中包含特定字符串的网址。我想将/new-site-connect替换为/financing

example.com/about-us/new-site-connect/lead-aba/?utm_source=InterestList&utm_medium=email&utm_campaign=campus1&utm_content=PreQualifyNow

example.com/about-us/financing/lead-aba/?utm_source=InterestList&utm_medium=email&utm_campaign=campus1&utm_content=PreQualifyNow

我尝试了以下方法。但没有人工作

RewriteRule ^/about-us/new-site-connect/(.*)$ /about-us/financing/$1 [R=301,L]
RewriteRule ^/about-us/new-site-connect(.*) /about-us/financing$1 [L,R=301]

请为此提供解决方案。

2 个答案:

答案 0 :(得分:1)

如果代码位于htaccess上下文中,则无法使用前导/个字符:

RewriteEngine On
RewriteRule ^(about-us)/new-site-connect/(.*)$ /$1/financing/$2 [R=301,L,QSA]

答案 1 :(得分:1)

最后我解决了这个问题。请找到以下解决方案:

重定向永久/ about-us / new-site-connect / example.com/about-us/financing /