Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite

Redirect Any Url *

         

Birdman

12:38 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I though I knew how to do this but I cannot get it right. I am basicall trying to redirect any url on the site to one script on my server.

Here's what I have, but I keep getting a 500 error:

RewriteEngine on

RewriteCond %{REQUEST_URI}!^curl_forward\.php$
RewriteCond %{QUERY_STRING} (.*)
RewriteRule (.*) /curl_forward.php?url=$1%1

Seems pretty basic, but no go and I have tried many variations. Can someone lend a hand here :)

Thanks!

jdMorgan

1:36 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a missing leading slash in the 'anti-looping' RewriteCond, and the pre-existing query string can be passed using [QSA], so this simpler version should do what you want:

RewriteCond %{REQUEST_URI} [b]!^/cu[/b]rl_forward\.php$
RewriteRule (.*) /curl_forward.php?url=$1 [b][QSA,L][/b]

You could also write it this way:

RewriteCond [b]$1[/b] [b]!^cu[/b]rl_forward\.php$
RewriteRule (.*) /curl_forward.php?url=$1 [b][QSA,L][/b]

Basically, the URLs 'seen' by RewriteRule in .htaccess never have a leading slash, while those in the %{REQUEST_URI} variable always have a leading slash. In httpd.conf or conf.d, both will have the leading slash. This is because .htaccess is a 'per-directory' config file, and URLs are automatically localized to the directory in which the code resides. So, if the .htaccess is located in "/", then the path to "/" is stripped before the code sees it. On the other hand, %{REQUEST_URI} is a global variable, so the slash is not stripped.

Also, this is an internal rewrite, not an external redirect, so let's be sure that the terminology agrees with what you want to accomplish.

Jim

Birdman

2:36 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks alot JD!

Perfect!

g1smd

1:02 am on Apr 28, 2007 (gmt 0)

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



>> this is an internal rewrite, not an external redirect <<

Good point. One that many miss.