使用多个查询重定向

时间:2016-12-15 13:34:53

标签: wordpress .htaccess redirect url-parameters

我一直在寻找几个小时,但找不到解决这个问题的工作方案。我正在重新设计一个网站,需要将一堆旧网址重定向到新网址。基本格式如下:pages/page.php?m=22&p=33应该像mainpage/subpage/那样完全忽略所有参数。在尝试了多种变体后,我目前在我的htaccess中有这个(作为Wordpress网站的一部分)。当url中有2个参数重定向而不是1或无时,就会出现问题。

# REDIRECTS FROM OLD WEBSITE
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# custom redirects
Options +FollowSymLinks -MultiViews
RewriteCond %{QUERY_STRING} ^m=([0-9]+)&p=([0-9]+)$ [nc]
RewriteRule ^pages/all_inclusive_zeildag\.php$ /bedrijfsuitjes/volledig\-verzorgd\-zeilen/ [R=301,NC,L]
</IfModule>
# END REDIRECTS OLD WEBSITE

# BEGIN WordPress
all the usual wp code
#
# END WordPress

我几乎得到了这个工作。问题是第二个参数。正确重定向是:  pages/all_inclusive_zeildag.php?m=8如果我没有任何参数重定向。

但问题是:/pages/all_inclusive_zeildag.php?m=8&p=22导致404

任何见解都非常受欢迎。

谢谢, 约翰

3 个答案:

答案 0 :(得分:0)

正如预期的那样,前两个没有被这个重写者接受。

第三个实际上正在做你要求它做的事情:

http://57755478.swh.strato-hosting.eu/pages/all_inclusive_zeildag.php?m=8&p=22

结果在301朝向: http://57755478.swh.strato-hosting.eu/bedrijfsuitjes/volledig-verzorgd-zeilen/?m=8&p=22

(使用devtools网络标签,如果您使用的是Chrome,请启用保留日志)

如果您打算删除查询字符串,则需要在重定向网址上附加问号:

RewriteRule ^ pages / all_inclusive_zeildag.php $ / bedrijfsuitjes / volledig-verzorgd-zeilen /? [R = 301,NC,L]

同样为了清楚起见,将RewriteCond语句与重写规则一起分组,因为它们仅适用于跟随它们的第一个RewriteRule。

祝你好运!

答案 1 :(得分:0)

&#34;很好&#34; 查看处理重写规则时发生的事情的方法是使用{{3}中的RewriteLogRewriteLogLevel指令}:

RewriteEngine On
RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 3

Apache 2.2 mod_rewrite使用常规Apache 2.4 mod_rewrite指令:

LogLevel alert rewrite:trace3

另请参阅:LogLevelhttps://wiki.apache.org/httpd/RewriteLog

答案 2 :(得分:0)

好。感谢所有的投入。不知何故,它让我走上了正确的轨道,我最终得到了


RewriteEngine On
#RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^pages/all_inclusive_zeildag\.php /bedrijfsuitjes/volledig-verzorgd-zeilen/%1? [L,R=301,NC]
RewriteRule ^pages/avondopleiding\.php /leren-zeilen/avondles-zeilen/%1? [L,R=301,NC]