301重定向:/article_list.php?parent_cat = 152& catid = 187 ???我该如何重定向?

时间:2013-11-25 00:07:00

标签: regex apache .htaccess mod-rewrite http-status-code-301

我在.htaccess中设置了301重定向,其中一个是:

Redirect 301 /article_list.php?parent_cat=152&catid=187 http://mysitehere.com/resources/objects/tribulus/

当我通过转到http://mysitehere.com/article_list.php?parent_cat=152&catid=187仔细检查它时,它会停留在该页面上,并显示404:找不到页面。我做错了吗?

2 个答案:

答案 0 :(得分:1)

您需要mod_rewrite规则来匹配查询字符串。请在DOCUMENT_ROOT/.htaccess文件中考虑此规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^parent_cat=152&catid=187$ [NC]
RewriteRule ^article_list\.php$ /resources/objects/tribulus/? [R=301,L,NC]

参考:Apache mod_rewrite Introduction

更新::您的完整.htaccess:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^parent_cat=152&catid=187$ [NC]
RewriteRule ^article_list\.php$ /resources/objects/tribulus/? [R=301,L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ /$1/ [L,R=301]

# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1/ [L]

答案 1 :(得分:0)

我相信Redirect模块的mod_alias指令根本不能真正处理/匹配查询字符串,参见其文件:

  

mod_alias旨在处理简单的URL操作任务。更多      复杂的任务,如操纵查询字符串,使用提供的工具      mod_rewrite

为了匹配查询字符串,建议您使用RewriteCond + RewriteRule组合,其中RewriteCond按字典顺序与%{QUERY_STRING}匹配。 :)