我的.htaccess文件是:
Redirect 301 http://domain.com/news/articles?dtMain_start=150 http://domain.com/news/articles
Redirect 301 http://domain.com/news/articles?dtMain_start=160 http://domain.com/news/articles
Redirect 301 http://domain.com/news/articles?dtMain_start=170 http://domain.com/news/articles
#
RewriteEngine On
RewriteBase /
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
我还必须加入以下规则
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.co.uk/$1 [R=301,L]
我不能让他们一起工作......任何人都可以帮忙......
我尝试在RewriteCond之前堆叠重定向,我得到了这个......
http://www.domain.com/news/articles?q=news/articles?dbMain_start=150
即http://domain.com/newpage?q=oldpage
好吧,Mod_Alias和Mod_Rewrite彼此不喜欢。
我可以写下这样的内容:
RewriteCond %{REQUEST_QUERY_STRING} ^.*&bodgeredirect=true$
RewriteRule ^(.*)&bodgeredirect=true$ index.php?q=$1 [L,QSA]
答案 0 :(得分:1)
首先:There is not mod_redirect. Redirect
是mod_alias的指令。
Redirect
指令与mod_alias的任何其他指令一样,仅适用于URL路径。因此,您的Redirect
指令将无法按预期工作。改为使用mod_rewrite等价物:
RewriteCond %{HTTP_HOST} =example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^dtMain_start=(150|160|170)$
RewriteRule ^news/articles$ /news/articles? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
一般情况下,如果模式彼此重合,则混合mod_alias和mod_rewrite不是一个好主意。