1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Apache RedirectMatch plus ScriptAliasMatch problem

Discussion in 'Apache' started by poddys, May 1, 2014.

  1. #1
    I originally posted this on Stackoverflow, but have had no responses and I need to resolve this. Trial and error are not easy since after each change I need to restart Apache and it's running the live web sites.

    I am so close to solving a problem where I need to redirect old pages from our web site to new ones, but for the life of me I can't get one of them to work, I keep getting a script error.

    It would be nice to do this in .htaccess, however unfortunately as well as changing the url we need to do a ScriptAliasMatch (SAM) which only works in httpd.conf.

    It's further complicated by the fact that our new web site has not yet gone live, so we have another domain pointing to the new location, and by taking a url from the old site and changing the domain to the new we can test the redirections.

    I will refer to "olddomain.com" and "newdomain.com" below because we don't want any of the new pages or the testing domain to end up in Google before we go live.

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

    http://www.olddomain.com/b2c/b2citmdsp.pgm?pp_skmno=18297
    Code (markup):
    and should be redirected to:

    http://www.newdomain.com/prodpage.pgm?item=18297
    Code (markup):
    I use a 301 redirect as follows to do this. The latest attempt looks like this:

    RedirectMatch 301 /b2c/b2citmdsp.pgm(.*)pp_skmno=(.*) http://www.newdomain.com/prodpage.pgm?item=$2
    Code (markup):
    I have a similar case where the parameter names have not changed and this works, but in this case the new program uses "item" for the parameter name not "pp_skmno"

    Having done this, there is a ScriptAliasMatch that follows that points to a folder where the .pgm's reside:

    ScriptAliasMatch (.*)\.pgm$ /QSYS.LIB/B2CRLIVE.LIB/$1.pgm
    Code (markup):
    For testing, I key the old url, then change the domain to the new one, and if the redirect works I expect to see the new version of the page in the new web site. Instead the error I am getting is:

    The script request is not valid. The script is not executable. 
    Code (markup):
    and in the Apache error log I see:

    /QSYS.LIB/B2CRLIVE.LIB/b2c is not a cgi program: /QSYS.LIB/B2CRLIVE.LIB/b2c
    Code (markup):
    Now since other redirects for .pgm's DO work I assume that the SAM is formatted correctly, but I am not sure why the "b2c" is taken as the first replace string.

    I know I am SO CLOSE, and curiously enough if instead of typing:

    http://www.olddomain.com/b2c/b2citmdsp.pgm?pp_skmno=18297
    Code (markup):
    I replace the "?" identifying the 1st parameter with "." as below:

    http://www.olddomain.com/b2c/b2citmdsp.pgm.pp_skmno=18297
    Code (markup):
    the redirect works perfectly. However I just can't seem to get the parameter on the url to be processed correctly.

    One thing I have not been able to find in the Apache documentation is exactly how redirects work if you have more than one rule that applies. Does the first matching rule change the url, and then the subsequent rules try to match to that, as well as the SAM? That's the only logical way I can see it working, but I could be wrong.

    Thanks for any help and I hope I managed to explain this adequately.

    (In case you are curious or this means anything to you - our server is an IBM iSeries running Apache under ZendServer 6, the SAM is necessary because the .pgm's are programs that have been created in RPG).
     
    poddys, May 1, 2014 IP