redirectMatch添加一个神秘的查询字符串

时间:2014-03-08 23:18:54

标签: apache .htaccess mod-rewrite redirect

我升级了某人的论坛,并且有数以万计的网址需要301重定向到他们的新家。例如:

http://www.elfquest.com/social/forum/thread/7851/posters-in-comics/post_572519/  

应该指向

http://www.elfquest.com/forums/discussion/7851/posters-in-comics/post_572519/

我找到了一个可以完成工作的redirectMatch:

redirectMatch 301 ^/social/forum/thread/(.*) http://www.elfquest.com/forums/discussion/$1

但它最后添加了一个好奇的查询字符串,如下所示:

http://www.elfquest.com/forums/discussion/7851/posters-in-comics/post_572519/?do=/forum/thread/7851/posters-in-comics/post_572519/

新的论坛软件(包括HTML搜索引擎中的正确标准参考)处理结果没有问题,但我真的很想让它“正确”。

这是我的.htaccess

redirectMatch 301 ^/social/forum/thread/(.*) http://www.elfquest.com/forums/discussion/$1

RewriteOptions inherit
php_value include_path .:/home/elfquestftp/public_html/phpcode
Addhandler application/x-httpd-php .html .htm
#php_flag register_globals on

RewriteEngine on

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

底部的东西是标准的Wordpress .htaccess东西。我也在wordpress块之前尝试过这个重写器......

RewriteEngine on
RewriteBase /
RewriteRule ^social/forum/thread/(.*)$ http://www.elfquest.com/forums/discussion/$1 [L,R=301]

......它似乎没有做任何事情。

1 个答案:

答案 0 :(得分:0)

请勿将mod_rewrite规则与mod_alias规则混合使用。将此RedirectMatch替换为:

RewriteEngine On

RewriteRule ^social/forum/thread/(.*) http://www.elfquest.com/forums/discussion/$1? [L,R=301,NC]
目标网址末尾的

?将删除任何现有的查询字符串。