Forum Moderators: phranque

Message Too Old, No Replies

301 redirect not working

redirecting to an image.

         

devkinetic

4:49 pm on Jan 14, 2009 (gmt 0)

10+ Year Member



I setup a 301 redirect in my .htaccess to catch all request to a script i used to have and go to an image. For some reason it's not working:

redirect 301 /cgi-bin/nph-test.pl/(.*) http://www.example.com/leeches/leech.gif

the .htaccess is in:
/home/exampl/public_html/

my cgi-bin directory is in:
/home/examp/public_html/cgi-bin/

Here is an example link i'm trying to redirect:
http://www.example.com/cgi-bin/nph-test.pl/010110A/http/www.google.com

Do I need anything else in my .htaccess to allow this to work? I have another redirect in there which works just fine:

redirect 301 /blog/ [blog.example.com...]

[edited by: jdMorgan at 5:19 pm (utc) on Jan. 14, 2009]
[edit reason] Please use example.com [/edit]

jdMorgan

5:18 pm on Jan 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be aware that the Redirect directive uses simple prefix-matching, and does not support the use of regular-expressions pattern matching. Therefore, it will probably treat "(.*)" as a literal string, and so will never detect a match or invoke your redirect.

Use RedirectMatch instead. See the Apache mod_alias documentation for important details.

Jim

devkinetic

6:00 pm on Jan 14, 2009 (gmt 0)

10+ Year Member



thanks for the quick reply. That makes perfect sense!

If I'm correct this would be the correct syntax?:

RedirectMatch 301 ^/cgi-bin/nph-test.pl/(.*)$ http://www.example.com/leeches/leech.gif

would that also catch when someone accesses just nph-test.pl without anything in the querystring?

jdMorgan

6:15 pm on Jan 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RedirectMatch cannot see the query string anyway, since it is not part of the URL, but rather data appended to the URL to be passed to the resource *at* that URL. Remember that the "L" in URL means "Locator" and that a query string has nothing to do with a resource's location on the Web. Therefore, Mod_alias URL-based directives have no "query-string awareness," and mod_rewrite requires a RewriteCond to examine query strings appended to URLs.

Your RedirectMatch syntax looks OK.

Jim

devkinetic

6:35 pm on Jan 14, 2009 (gmt 0)

10+ Year Member



I see. Thank you so much.

The purpose of this redirect was to make people aware they were abusing my server resources by still accessing the since removed script. I appreciate the clear and detailed answers you provided. If we should ever meet in real life, I most definately owe you a pint :)