使用查询字符串重定向URL

时间:2013-05-23 22:22:38

标签: .htaccess mod-rewrite redirect

我有一个带有查询字符串的网址,我正在尝试重定向,但我无法让它工作。原始URL不仅有一个查询字符串,它是一个Joomla SEF URL并包含一个?在URL内也是如此。一团糟。这是原始网址:

http://www.domain.com/menu-item/item/1234-article-title-here?.html&utm_source=XYZ&utm_medium=ABC&utm_campaign=the+campaign+name

我尝试了几种不同的重写条件和规则,我尝试过的都没有。我也将.htaccess中的语句放在根目录中,因为没有实际的子目录。查询字符串不需要传输。

我尝试过这个并没有用:

RewriteCond %{REQUEST_URI}  ^/menu-item/item/1234-article-title-here\?\.html$
RewriteRule ^(.*)$ http://www.domain.com/new-page.html? [R=302,L]

我也试过

RewriteCond %{REQUEST_URI}  ^/menu-item/item/1234-article-title-here$
RewriteRule ^(.*)$ http://www.domain.com/new-page.html? [R=302,L]

这个

RewriteCond %{REQUEST_URI}  ^1234-article-title-here\?\.html$
RewriteRule ^(.*)$ http://www.domain.com/new-page.html? [R=302,L]

和这个

RewriteCond %{REQUEST_URI}  ^1234-article-title-here$
RewriteRule ^(.*)$ http://www.domain.com/new-page.html? [R=302,L]

以及@jon lin的答案。我最终找到了一个有效的重定向,发布在下面。

2 个答案:

答案 0 :(得分:1)

这最终结束了工作:

RewriteCond %{REQUEST_URI}  ^/menu-item/item/1234-article-title-here$
RewriteRule ^(.*)$ http://www.domain.com/new-page.html? [R=302,L]

答案 1 :(得分:0)

你试过了吗?

RewriteEngine On
RewriteCond %{QUERY_STRING} ^\.html&utm_source=XYZ&utm_medium=ABC&utm_campaign=the+campaign+name$
RewriteRule ^menu-item/item/1234-article-title-here$ /page-you-want-to-redirect-to? [L,R=301]

目标末尾的?会删除查询字符串,以便它不会包含在重定向中。

相关问题