Forum Moderators: phranque

Message Too Old, No Replies

My external redirect rule doesn't work

code to redirect to an external url

         

Grimmjow

12:54 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



Hi.

My code to redirect to an external link doesn't work, I hope to find some useful suggestion in this place.

I read this post before posting, [webmasterworld.com...] and I hoped that the answer of jdMorgan would helped me, but I think I'm still making something wrong.

This is my .htaccess:

php_flag register_globals 0
rewriteEngine On
# trailing slash fix
rewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
rewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
# www. fix
rewriteCond %{HTTP_HOST} !^www\.
rewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# external redirect
rewriteRule ^www\.example\.com/statistics/$ http:[b]//www.othersite.com/ [R=301,L][/b]

The bold rule doesn't work. I tried putting http:// after ^ and before www\. but still doesn't work.

Basically I want to redirect a folder (statistics/ in my case, that couldn't even exists), to an external url.

Could anyone help me out to solve this?

Thanks in advance.

[edited by: jdMorgan at 1:54 pm (utc) on Sep. 15, 2007]
[edit reason] example.com [/edit]

Grimmjow

1:09 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



Weel, actually I solved with this simple line:

redirect 301 /statistics http://www.othersite.com

But I'm still curious why the rewriteRule didn't work if anyone has the time to look on it ;)

Thank you.

[edited by: jdMorgan at 1:55 pm (utc) on Sep. 15, 2007]
[edit reason] De-linked [/edit]

jdMorgan

1:52 pm on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule looks only at the local URL-path, and you've included the protocol and domain name in the pattern as well. So the pattern will never match and the rule will never be invoked. Correct .htaccess syntax would be:

RewriteRule ^statistics/$ http://www.othersite.com/ [R=301,L]

assuming that you only want to redirect requests for that exact local URL-path.

If you wish to examine the domain name, then use a RewriteCond to test HTTP_HOST as in your other example rule.

Jim

[edited by: jdMorgan at 1:55 pm (utc) on Sep. 15, 2007]

Grimmjow

6:51 pm on Sep 15, 2007 (gmt 0)

10+ Year Member



Thank you for the exhaustive explanation JD.