Question

I want to redirect all pages that call a script to call a different script and also to change the name of a parameter. I also want to lose a folder from the url. No matter what I try I get an error.

For testing purposes before we go live on the new site, where these pages will be redirected, we have a domain set up that points to the new file locations and need to change that too as part of the redirect (after we go live the old domain will be pointed to the new domain location).

Because the url calls a program (prodpage.pgm) and Srcipt Aliases are also needed, this redirect MUST be done in the httpd.conf file not in .htaccess, which means I have to restart Apache every time I change anything, so I can't just

The old url we want to redirect is of the form:

 http://www.olddomain.com/b2c/b2citmdsp.pgm?pp_skmno=18297

and should be redirected to:

 http://www.newdomain.com/prodpage.pgm?item=18297

I use a 301 redirect as follows to do this but it doesn't work:

RedirectMatch 301 ^/b2citmdsp.pgm\?pp_skmno=(.*) http://www.newdomain.com/prodpage.pgm?item=$1

In summary, I need to:

(a) lose the /b2c/ (b) change b2citmdsp.pgm to prodpage.pgm (c) retrieve the parameter value for pp_skmno and use it with the new url

Any ideas on what I am doing wrong please, or is this just not possible.

Also, when you do a redirect, does it change the url, so that you can use a subsequent redirect to further modify it? In this case I might be able to use 2 or 3 redirects, but I feel sure this must be possible in one, it's just I struggle with regex sometimes.

Was it helpful?

Solution

You can match the following regex:

http:\/\/.+\/b2citmdsp\.pgm[^=]+=(.*)

and replace with:

http://www.newdomain.com/prodpage.pgm?item=\1

Demo

OTHER TIPS

I did finally resolve this problem, but unfortunately it wasn't purely using Apache redirects.

I wanted to change the name of the program as well as the name of a parameter, but kept getting script errors, no matter what regex I tried.

However, I have another redirect which only had to change the name of a program and that worked fine.

So, I changed my problem redirect to just change the name of the program, which meant it called it with the old name of the parameter. I then changed the program so that the first thing it did was to check if the old parameter had been passed, and did it's own redirect to use the correct parameter.

That's maybe a bit clunky, but it works, problem solved, and it's almost instant and transparent to the visitor.

Thanks for your help everyone. Just goes to show that sometimes you don't need to shoot for the moon and get the perfect answer, as long as you find a solution that works and seems to work well that's good enough.

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