Forum Moderators: phranque

Message Too Old, No Replies

301 redirect from dynamic URL to static

Need to redirect from cgi script (with params) to static url

         

garrett

3:38 pm on Sep 19, 2008 (gmt 0)

10+ Year Member



I'm having trouble redirecting some dynamic URLs to a static one on a different domain. Dynamic URLs look something like this:
example.com/folder1/folder2/script.cgi?param1=xx&param2=xx&param3=xx..etc.

I want ALL urls that follow this format to redirect to a static page on a new domain. For example: newdomain.com/new-static-page/

I can't figure out how to do this without all of the parameters coming along for the ride. So, my urls end up looking like newdomain.com/new-static-page/?param1=xx&param2=xx&param3=xx

I don't care about the params since the cgi script on the old domain is dead.

Thanks.

jdMorgan

3:43 pm on Sep 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your code as a basis for discussion.

If using mod_rewrite, add a question mark to the end of the substitution URL to clear the query string, as described in the Apache RewriteRule documentation.

Jim

garrett

7:11 pm on Sep 26, 2008 (gmt 0)

10+ Year Member



Here is the code that I'm using now:

Redirect 301 /folder1/folder2/script.cgi [newdomain.com...]

This will redirect all urls w/ params after the ".cgi"...but the params get appended to the new destination (which I don't want). I've tried constructing some more advanced mod_rewrites, but I keep borkin it up.

Thanks.

g1smd

8:56 pm on Sep 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here is how I would do it...

RewriteRule [b]^[/b]folder1/folder2/script.cgi[b]$[/b] http://www.example.com/new-static-page/[b]?[/b] [R=301,L]

The ? clears the query string from the new URL.

It redirects whether the original request has a query string, or not.

It redirects from both www and non-www on the old domain.

Never mix Redirect and RewriteRule rules in the same .htaccess file, so do make sure that all of your other rules do *not* use Redirect.

garrett

9:48 pm on Sep 26, 2008 (gmt 0)

10+ Year Member



Thanks for the code, I'll give that a shot. My htaccess DOES have several other Redirect rules, so I guess I'll have to convert those to RewriteRule as well. Assuming the code you gave works (I'm sure it will) it shouldn't be too hard to convert the other ones.

g1smd

10:12 pm on Sep 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I rarely test the code I post here (unless it is a chunk lifted from a live server), so you need to test and adapt it to your needs.

I do make some mistakes, wrong assumptions, typos, and complete screw-ups, from time to time, most days.

garrett

11:29 pm on Sep 26, 2008 (gmt 0)

10+ Year Member



I'll test it out this weekend and report back w/ results.