用多个查询重定向



我现在一直在搜索数小时,但是找不到解决此问题的工作解决方案。我正在重新设计一个网站,需要将一堆旧URL重定向到新URL。基本格式类似于: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

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

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

任何洞察力都受到欢迎。

谢谢约翰

前两个未被预期的重写。

第三名实际上是在做您要它要做的事情:

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

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

(使用DevTools网络选项卡,并在使用Chrome(如果使用Chrome)的情况下打开保存日志)

如果您打算要剥离的查询字符串,则需要将问号附加到重定向URL:

重写 ^页面/all_inclusive_zeildag.php $/bedrijfsuitjes/volledig-veredig-verzorgd-zeilen/?[r = 301,nc,l]

也为了清楚起见,将重新写入语句与重写规则组合在一起,因为它们仅适用于后的第一个重写器。

祝你好运!

a " nice" 查看处理重写规则时发生的事情的方法是使用rewritelog和rewriteLoglevel指令2.2 mod_rewrite:

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

或在Apache 2.4 Mod_rewrite中使用常规Loglevel指令:

LogLevel alert rewrite:trace3

另请参阅:https://wiki.apache.org/httpd/rewritelog,https://stackoverflow.com/a/9632952/832620

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

重新创新#rewriteCond%{script_filename}!-f重写 ^页面/all_inclusive_zeildag  .php/bedrijfsuitjes/volledig-verzorgd-zeilen/%1?[L,r = 301,NC]重写 ^页/avondopleiding  .php/leren-zeilen/avondles-zeilen/%1?[L,r = 301,NC]

最新更新