Question

I'm trying to redirect a list of URLs, but any of them that have a ? it isn't working. For example, here's my line of code...

Redirect 301 /calendar-of-events/day/date/2013-03-28/227.html?print=1&tmpl=component https://example.com/index.php/calendar/

This doesn't redirect. However, if I use this...

Redirect 301 /calendar-of-events/day/date/2013-03-28/227.html https://example.com/index.php/calendar/

...or this...

Redirect 301 /calendar-of-events/day/date/2013-03-28/227.html&tmpl=component https://example.com/index.php/calendar/

...and test the URLs out, they redirect correctly.

Any ideas on how to get this working?

Was it helpful?

Solution

You can't match query string using Redirect directive. Use mod_rewrite instead:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^print=1&tmpl=component$ [NC]
RewriteRule ^calendar-of-events/day/date/2013-03-28/227\.html$ https://example.com/index.php/calendar/? [L,R=301]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top