在.htaccess和preserve查询字符串替换URL的一部分 [英] Replace portion of URL in .htaccess and preserve query string
问题描述
我发了封邮件出去的许多的人以错误的URL,并且需要用的.htaccess解决它。错误的网址:
<$p$p><$c$c>https://amemoirproject.com/chapters/leaving-tanglewood/?utm_medium=email&utm_campaign=Chapter+15+The+Anointed&utm_content=Chapter+15+The+Anointed+CID_6d1662ca75fabbdcbd66397fc00cdcf4&utm_source=Campaign%20Monitor&utm_term=Chapter%2015%20The%20Anointed%20%20A%20Long-Haired%20Handsome%20Jesus
正确的URL:
<$p$p><$c$c>https://amemoirproject.com/chapters/the-anointed/?utm_medium=email&utm_campaign=Chapter+15+The+Anointed&utm_content=Chapter+15+The+Anointed+CID_6d1662ca75fabbdcbd66397fc00cdcf4&utm_source=Campaign%20Monitor&utm_term=Chapter%2015%20The%20Anointed%20%20A%20Long-Haired%20Handsome%20Jesus
唯一的区别是目录从的改变而使格尔伍德
到的恩膏
。我需要保留查询字符串,这应该是一个302。
建议?
修改
如果原来不正确的URL包含以下查询参数和值这302重定向,才会发生:
utm_campaign =章+ 15 +的+涂油
到的httpd.conf
启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_ROOT
目录下:
选项+了FollowSymLinks -MultiViews
#开启mod_rewrite的上
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{QUERY_STRING}(^ |&安培;)utm_campaign =章\ +15 \ +的\ +涂油(安培; | $)[NC]
重写规则^(章)/离开格尔伍德/?/ $ 1 /的恩膏/ [L,NC,R = 302]
I sent an email out to lots of people with the wrong URL and need to fix it with .htaccess. The wrong URL:
https://amemoirproject.com/chapters/leaving-tanglewood/?utm_medium=email&utm_campaign=Chapter+15+The+Anointed&utm_content=Chapter+15+The+Anointed+CID_6d1662ca75fabbdcbd66397fc00cdcf4&utm_source=Campaign%20Monitor&utm_term=Chapter%2015%20The%20Anointed%20%20A%20Long-Haired%20Handsome%20Jesus
The correct URL:
https://amemoirproject.com/chapters/the-anointed/?utm_medium=email&utm_campaign=Chapter+15+The+Anointed&utm_content=Chapter+15+The+Anointed+CID_6d1662ca75fabbdcbd66397fc00cdcf4&utm_source=Campaign%20Monitor&utm_term=Chapter%2015%20The%20Anointed%20%20A%20Long-Haired%20Handsome%20Jesus
The only difference is the change of the directory from leaving-tanglewood
to the-anointed
. I need to retain the query string, and this should be a 302.
Suggestions?
EDIT
This 302 redirect should only occur if the original incorrect URL contains the following query parameter and value:
utm_campaign=Chapter+15+The+Anointed
Enable mod_rewrite and .htaccess through httpd.conf
and then put this code in your .htaccess
under DOCUMENT_ROOT
directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)utm_campaign=Chapter\+15\+The\+Anointed(&|$) [NC]
RewriteRule ^(chapters)/leaving-tanglewood/?$ /$1/the-anointed/ [L,NC,R=302]
这篇关于在.htaccess和preserve查询字符串替换URL的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!