Question

Been reading much Q&A about this in StackOverflow, but can't seem to find the solution I need.

I have an old url that has many possible query strings / parameters appended to it (too many to do line-by-line matching). I have a new url that is going to handle these requests but need to 301 redirect to the new url with any/all parameters intact...

oldscript.php (many combinations of parameters could be appended to the inbound url) newscript.php (append ? and any parameters found with oldscript.php)

This must be easier than I am making it, but all the examples have me pruning parameters one at a time and there are over 20 that could be included in any order or combination or none.

Looking for an apache .htaccess way to silently redirect the inbound visitor to the new script and pass any/all query parameters along to the new script.

Thanks gurus...

Note: I have done a quick and dirty PHP mod to the top of the oldscript for now but there must be a better way...

$params = explode('?',$_SERVER['REQUEST_URI']);
header( 'Location: http://www.mysite.com/newscript.php?'.$params[1]) ; die;
Was it helpful?

Solution

A simple rule like this should take care of that:

RedirectMatch 301 "^/oldscript\.php$" /newscript.php

Note that any existing query string will automatically be carried over to the new URI.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top