ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Problem Creating Redirects In Apache

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem Creating Redirects In Apache

    Our Apache configuration is currently set up so that both of our domains (for B2C and B2B) point to HTDOCS, and although you aren't supposed to be able to, you can access the pages applicable for both using either domain, which is REALLY BAD for Google and it also makes programming using relative links for files/images tricky.

    I have been working on a complete rewrite of our B2C site, which will have the same domain as the old, but for testing purposes I have employed a new domain and set this up using VirtualHost in Apache and what I want to do when we go live is to redirect the pages from the old site (as far as possible) to the correct ones on the new site.

    We also use Websmart ILE, so that many of the pages on the old and new sites actually run RPG programs, so we use ScriptAliasMatch to point to the AS400 Libraries in this case.

    The old links are of the format: domain.com/b2c/oldpage.pgm?parm=12345
    The new links would be: domain.com/newpage.pgm?newparm=12345

    The problem is how to do these redirects. The frustrating thing is that we don't have a test machine, and every time I make a change I have to stop/start Apache, which is not good in a live environment, so I need to try and get this right in as few tries as possible for obvious reasons.

    What I currently have is:

    ##301 REDIRECTS FOR OLD B2C PAGES
    Redirect 301 /b2c/B2CITMDSP.pgm?pp_skmno=(.*) /prodpage.pgm?item=$1

    # Programs use B2CRLIVE (Change this to match Websmart program library)
    ScriptAliasMatch (.*)\.pgm$ /QSYS.LIB/B2CRLIVE.LIB/$1.pgm

    The first part is supposed to strip off the "b2c" and convert the old page id and parameter to the new page id and parameter.
    The second part is supposed to point the program to the AS400 library (B2CRLIVE).

    So, my call to:



    is supposed to redirect to:



    The error I get is:

    /QSYS.LIB/B2CRLIVE.LIB/b2c is not a cgi program: /QSYS.LIB/B2CRLIVE.LIB/b2c

    So somehow I am picking up "b2c" as my first parameter in the replace, not the program name.

    I know this is rather complicated to explain, but I could use a point in the right direction if anyone is more knowledgeable on Apache configuration than I am.

    I am assuming (since I can't see it documented anywhere) that each replace/match statement alters the url, and therefore if I strip off the "b2c" in one statement the next one won't see it.

    If this works I plan to do the same for the B2B site so that it points directly to it's own sub-folder in HTDOCS and not to the root.

    Any help and guidance would be much appreciated. I think I am close to solving this, but as I said I can't just keep using trial and error since I can't keep restarting the live Apache.
    Poddys Rambles On

  • #2
    Re: Problem Creating Redirects In Apache

    I think this might work:

    Redirect 301 /b2c/B2CITMDSP.pgm?pp_skmno=(.*) http://www.domain.com/prodpage.pgm?item=$1

    Just have to wait to restart Apache to try it out.
    Poddys Rambles On

    Comment


    • #3
      Re: Problem Creating Redirects In Apache

      Tried to edit the previous post and it wouldn't save for some reason. I wanted to add more information....

      I think this might work:

      Redirect 301 /b2c/B2CITMDSP.pgm?pp_skmno=(.*) http://www.domain.com/prodpage.pgm?item=$1

      Just have to wait to restart Apache to try it out.

      ------------------------------------------------

      It doesn't unfortunately, but getting closer...

      The following works perfectly where I have redirected a fixed page:

      Redirect 301 /b2c/b2ccontact.pgm http://domain.com/contact.php

      but where I have redirected using parameters:

      Redirect 301 /b2c/b2citmdsp.pgm?pp_skmno=(.*) http://www.domain.com/prodpage.pgm?item=$1

      it fails with this in Firefox:

      The script request is not valid. The script is not executable.

      and in the Apache error log:

      /QSYS.LIB/B2CRLIVE.LIB/b2c is not a cgi program: /QSYS.LIB/B2CRLIVE.LIB/b2c

      The 2 redirects in the HTTPD.CONF are:

      Redirect 301 /b2c/b2citmdsp.pgm?pp_skmno=(.*) http://www.drapertools.org.uk/prodpage.pgm?item=$1
      ScriptAliasMatch (.*)\.pgm$ /QSYS.LIB/B2CRLIVE.LIB/$1.pgm


      To recap... if it worked it should have redirected:

      http://www.domain.com/b2c/b2citmdsp.pgm?pp_skmno=19237

      to

      http://www.domain.com/prodpage.pgm?item=19237

      So now I am stuck again, but will keep hunting.
      All the fixed page redirects seem to work ok, it's just where variables are involved I am having trouble.
      Poddys Rambles On

      Comment

      Working...
      X