Forum Moderators: phranque

Message Too Old, No Replies

help a n00b with redirect loop

redirect loop

         

baldy

3:35 pm on May 3, 2009 (gmt 0)

10+ Year Member



Here's the deal:

I just want to redirect example.com and/or "all public domains" to example.com/blog but I keep getting a redirect loop.

I'm on cpanel using it's redirect tool.

If it matters I'm redirecting from the public index to a wordpress folder.

I have very little idea of what I'm doing so keep it elementary if you can please.

Is there a little bit of code that I can enter into htaccess that will stop this loop?

Thanks in advance

jdMorgan

6:15 pm on May 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I'm on cpanel using it's redirect tool.

That's the problem, as cPanel can only "write" very-general code, and can't handle "special requirements."

You also likely want an internal rewrite, rather than an external redirect.

You'll have to code this using mod_rewrite, and the outline will be:

If not already rewritten to /blog/
Prepend /blog to the requested URL-path, and rewrite to resulting filepath.

Jim

baldy

1:46 am on May 4, 2009 (gmt 0)

10+ Year Member



Okay, I realize that I probably shouldn't be messing around with this being so ignorant on the subject but that was over my head.

Here's what I have:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^.*$ "http\:\/\/www\.mysite\.com\/blog" [R=301,L]

This causes a loop, what should I add/change/set on fire/hit with hammer?

jdMorgan

2:32 pm on May 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteEngine on
#
# If not already rewritten to /blog/
RewriteCond %{REQUEST_URI} !/blog/
# Rewrite all requests to prepend "/blog/" to the filepath
RewriteRule ^.*$ http:\\www.example.com/blog/ [R=301,L]

It wasn't clear why you felt you needed to test the hostname for "any value." If you wish to invoke this rule only for specific hostnames, or to prevent this rule from being invoked for specific hostnames, then you might wish to include a RewriteCond to test for that condition. But there is no need to test it for "any value whatsoever" as you did.

Jim