homepage Welcome to WebmasterWorld Guest from 54.204.94.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
RedirectMatch with ScriptAliasMatch
Having problems with RedirectMatch with ScriptAliasMatch for a url in APach
poddys




msg:4668019
 3:51 pm on May 2, 2014 (gmt 0)

I have some urls that need to be redirected from our old site to our new one, but some run .pgm's which need to be pointed to a cgi-bin directory, which forces us to put all the redirects into the httpd.conf file not .htaccess.

I have got most of these working, but am struggling with one in particular where I need to match the name of the program and also change the value of a parameter.

I am assuming that each RedirectMatch changes the url that was submitted, so that by the time Apache gets to the ScriptAliasMatch the url mas been re-mapped correctly and this works on that rather than the original url?

For testing purposes (before our new site goes live) we are mapping the urls to a different domain, which points to the new file locations on the server.

The original url is:

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

and we want it to be mapped to:

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

The RedirectMatch I am using (which works according to regex101.com) is:

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

The ScriptAliasMatch I am using is:

ScriptAliasMatch (.*)\.pgm$ /QSYS.LIB/B2CRLIVE.LIB/$1.pgm

but I keep getting an error:

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

The program name that ought to be picked up is "prodpage" and "b2c" is a folder in the old url that should have been removed by the RedirectMatch.

Any ideas please?

 

lucy24




msg:4668072
 6:26 pm on May 2, 2014 (gmt 0)

one in particular where I need to match the name of the program and also change the value of a parameter

Quick answer: Dump mod_alias (Redirect by that name). I don't mean delete it! Just stop using it for redirects. You need to use mod_rewrite (RewriteRule). It sounds as if it's your own server, so if you still need to use htaccess, make sure the FollowSymLinks option is set.

The details of your question will be addressed by someone who speaks Apache. "RedirectMatch" is just the part that jumped out at me.

phranque




msg:4668158
 5:49 am on May 3, 2014 (gmt 0)

welcome to WebmasterWorld, poddys!


RedirectMatch will match the path but not the query string.
you need mod_rewrite directives for this.

poddys




msg:4668832
 11:22 am on May 6, 2014 (gmt 0)

Thanks for the help both of you.

Since I need to change the program (script) name prior to doing a ScriptAlias I am pretty sure I have to do the redirect in httpd.conf, although .htaccess would be a lot easier.

I know that redirecting to change the program name does work, I just can't get the change of the parameter name to work.

So I bit the bullet and modified the program so that it checks to see if it has been called with the old parameter name. If so it redirects to use the new parameter name.

Seems a bit clunky doing this, but hopefully there won't be too many of these after a while, and the redirect works fast, it's also transparent to the visitors.

lucy24




msg:4668951
 5:41 pm on May 6, 2014 (gmt 0)

I just can't get the change of the parameter name to work.

Well, you won't get it to work with mod_alias (Redirect or RedirectMatch) alone.

phranque




msg:4669380
 6:05 am on May 8, 2014 (gmt 0)

I know that redirecting to change the program name does work, I just can't get the change of the parameter name to work.

that's why i suggested you would need mod_rewrite for your solution.

So I bit the bullet and modified the program so that it checks to see if it has been called with the old parameter name. If so it redirects to use the new parameter name.

Seems a bit clunky doing this, but hopefully there won't be too many of these after a while, and the redirect works fast, it's also transparent to the visitors.

this is a perfectly legit method.
one disadvantage is that your server logs will typically show a 200 status code under these circumstances instead of a 301.

lucy24




msg:4669381
 6:42 am on May 8, 2014 (gmt 0)

your server logs will typically show a 200 status code under these circumstances instead of a 301

Setting aside the server: Will visitors see an upfront 301 or an in-page redirect? (The latter is a problem if you've got a security-conscious browser that puts up a stink when a page wants to redirect you. I don't suppose search engines like it much either.) If visitors receive the intended response, it doesn't much matter how it was generated.

That's assuming this approach doesn't end up consuming far more server resources than a mod_rewrite redirect would have done.

poddys




msg:4669392
 7:56 am on May 8, 2014 (gmt 0)

I don't expect too much traffic via the old links, and we might be able to add a separate section to tell the search engines to de-index these. Agreed a 301 would be best.

My main priority is to be able to accurately redirect as many old links to new as possible, and I think I now have 100%, with the exception of where we have completely modified the product categories, and I don't think that adding a LOT of redirects is worthwhile in this case, I just redirect all of those to the full product range page.

The problem I couldn't get around was that because the url runs a script and we had to tell the server to do an alias, it's necessary (or at least I believe it is) to modify the url in the httpd.conf file.

Still learning Apache though, and there are so many ways of redirecting/modifying, it takes a lot more than reading the manuals to comprehend it all and to understand the best ways of doing things.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved