I've been searching for hours now but cannot find the working solution for this problem. I'm redesigning a website and need to redirect a bunch of old url's to new url's. The basic format is something like:pages/page.php?m=22&p=33should go to something like mainpage/subpage/ while completely ignoring all parameters. After having tried multiple variations I currently have this (as part of a Wordpress site) in my htaccess. The problem arises when having 2 parameters in the url to redirect instead of 1 or none.
# 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
I have almost got this working. Problem is the second parameter. Properly redirected are: pages/all_inclusive_zeildag.php?m=8 and if I redirect without any parameter at all.
But the problem is:/pages/all_inclusive_zeildag.php?m=8&p=22 which leads to a 404
Any insight are more than welcome.
Thanks, John
The first two are not being picked up by this rewriterule, as expected.
The 3rd is actually doing exactly what you're asking it to do:
http://57755478.swh.strato-hosting.eu/pages/all_inclusive_zeildag.php?m=8&p=22
Results in a 301 towards: http://57755478.swh.strato-hosting.eu/bedrijfsuitjes/volledig-verzorgd-zeilen/?m=8&p=22
(Use devtools network tab, and turn on preserve logs if you're using chrome)
If you intended the query string to be stripped, then you'll need to append a question mark to the redirect url:
RewriteRule ^pages/all_inclusive_zeildag.php$ /bedrijfsuitjes/volledig-verzorgd-zeilen/? [R=301,NC,L]
Also for clarity, group the RewriteCond statements together with the rewrite rule, since they will only apply to the first RewriteRule following them.
Good luck!