Forum Moderators: phranque

Message Too Old, No Replies

Adding a second rewrite

Trying to update my site and redirect directories

         

adrock31

6:01 pm on Aug 3, 2005 (gmt 0)

10+ Year Member



Hi, sorry for the newby question but I'm trying to do two things with rewrites.

1. make "mysite.com" redirect to "www.mysite.com"

I've got that covered using the following .htaccess code.

RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mysite\.com [NC]
RewriteRule (.*) [mysite.com...] [R=301]

2. make www.mysite.com/test/whatever.php redirect to www.mysite.com/whatever.php

This is what I'm not sure on. I imagine it's simple, but I am having a hard time getting my head around this. I'm not a programmer, so please be patient. The reason I want to do this is that I took a test section of my site (test blog) and it is doing good and now has better PR than my homepage. So, I want to perm-redirect it to my homepage, however, there are a lot of sites linking to www.mysite.com/test/whatever....

Thanks in advance (ps. I copied the content already, so once the redirect works, there will be files to serve)

ChadSEO

6:10 pm on Aug 3, 2005 (gmt 0)

10+ Year Member



adrock,

The following line should do what you need:

RewriteRule ^test/(.*)$ /$1 [R=301]

adrock31

6:30 pm on Aug 3, 2005 (gmt 0)

10+ Year Member



Thanks for the response, but it didn't work.

This is what I entered.

RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mysite\.com [NC]
RewriteRule ^test/(.*)$ /$1 [R=301]
RewriteRule (.*) [mysite.com...] [R=301,L]

I also tried this

RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mysite\.com [NC]
RewriteRule (.*) [mysite.com...] [R=301]
RewriteRule ^test/(.*)$ /$1 [R=301,L]

neither worked.
"Redirection limit for this URL exceeded. Unable to load the requested page. This may be caused by cookies that are blocked."

jdMorgan

6:39 pm on Aug 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should specify a canonical URL when using the [R] flag to produce an external redirect:

RewriteEngine On
#
RewriteRule ^test/(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Jim

adrock31

6:45 pm on Aug 3, 2005 (gmt 0)

10+ Year Member



I wish I could say I understand what you meant by "canonical URL" but I am happy to announce that it did the trick.

Thanks a lot guys, I really appreciate your help.

Vive le WebmasterWorld!