Forum Moderators: phranque

Message Too Old, No Replies

301 redirect problem

         

rack

4:23 pm on May 12, 2007 (gmt 0)

10+ Year Member



Hello, I hope this is in the correct place, if not someone please redirect me. :)

I have a website with the files in the root directory, it has a Google page rank of 5.
example.com/
I have a blog with the files in a subdirectory, it has a page rank of 4.
example.com/serendipity/
I want the existing external links to end up at the blog with the domain page rank of 5. Though at the point of frustration I am with this, I don't care that much about the page rank anymore! :)

I use the following 301 in the htaccess file of the root.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://example.com/serendipity/$1 [R=permanent,L]

My problem is that the page rank does not carry over and I can no longer access the website which I want people to do from my internal links. I assume my problem is that the 301 not only redirects example.com, but also example.com/index.htm(l).

Anyone know how I am screwing this up?

RJ

[edited by: jdMorgan at 5:07 pm (utc) on May 12, 2007]
[edit reason] example.com, please, See TOS. [/edit]

jdMorgan

5:27 pm on May 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code is doing exactly what you asked it to do -- It redirects every request for every URL in example.com to example.com/serendipity/. The problem comes in because it also redirects example.com/serendipity/ to example.com/serendipity/serendipity/ to example.com/serendipity/serendipity/serendipity, etc., etc., just as you asked it to, until either the server or the browser reaches its maximum redirection limit.

Each time a redirect is invoked, the current HTTP transaction is terminated, and the client (e.g. browser) starts a new HTTP request with the new URL given in the redirect response; The server itself does not remember anything about any previous requests, so there's nothing to stop this loop.

You'll need to tell it NOT to redirect /serendipity, so that this redirect happens only once:


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

As to PageRank passing to the internal pages, this will take up to several months, depending on where G is in their crawling/ranking cycle -- Say, one month to crawl and index the new URLs, and another month --or maybe several-- until the TBPR is updated; Updating browser Toolbar PR is not a priority at Google.

Also, if you wish *all* requests for example.com to go to the forum, and you cannot move the forum into the root directory (or don't want to), but you don't want or need the forum's subdirectory (serendipity) to appear in the URL, then use this instead:


RewriteEngine on
#
# If direct client request for forum subdirectory
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /serendipity
# externally redirect back to main domain
RewriteRule ^serendipity/(.*)$ http://example.com/$1 [R=301,L]
#
# Internally rewrite all requests to forum subdirectory
RewriteCond %{HTTP_HOST} ^example\.com
RewriteCond $1 !^serendipity/
RewriteRule (.*) /serendipity/$1 [L]

The second rule will make it appear that all files in /serendipity are at the root URL of your site -- the subdirectory path becomes 'invisible' to users. The first rule is used to correct subdirectory URLs that have already been indexed by search engines.

Jim