我在.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:找不到页面。我做错了吗?
答案 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]
更新::您的完整.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}
匹配。 :)