Forum Moderators: phranque

Message Too Old, No Replies

301 redirects for internal link changes

         

riospace

10:34 pm on Oct 21, 2006 (gmt 0)

10+ Year Member



I recently changed my internal links to point to directories instead of files. Unfortunately, I did not do any redirects and my traffic instantly fell by over 30%.

This is how my current .htaccess file is set up:

DirectoryIndex index.php index.html index.htm

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

redirect 301 /example.html http://www.example.com/index.php

This is how I tried to setup my .htaccess file to redirect all of my internal link changes:

DirectoryIndex index.php index.html index.htm

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

redirect 301 /index.html http://www.example.com/

redirect 301 /index.php http://www.example.com/

redirect 301 /widget1/example.html http://www.example.com/widget1/

redirect 301 /widget2/index.html http://www.example.com/widget2/

redirect 301 /level1/widget3/index.html http://www.example.com/level1/widget3/

redirect 301 /level1/widget4/index.html http://www.example.com/level1/widget4/

redirect 301 etc.....

When I tried the above .htaccess file codes, the site would no longer come up and was giving a server error message. I thought maybe the following lines where causing the problem:

redirect 301 /index.html http://www.example.com/

redirect 301 /index.php http://www.example.com/

I changed the above to:

redirect 301 /example.html http://www.example.com/index.php

and kept the rest of the internal link change 301's, but I still only got server errors.

What am I doing wrong?

g1smd

1:07 am on Oct 22, 2006 (gmt 0)

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



To redirect index pages to files, try this:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ http://www\.domain\.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www\.domain\.com/$1 [R=301,L]

It works for all index files, .html, .htm, .php, whether in the root or in a folder.

The index redirect must be first, otherwise you create an unwanted redirection chain.

riospace

1:18 am on Oct 22, 2006 (gmt 0)

10+ Year Member



Will this work for index.htm files too?

Will the code you gave me help me with the search engine problem I am having?

Also, will this code cause a problem with the the links to index.htm and index.html files that I have not changed to point to the related directory?

riospace

9:14 am on Oct 22, 2006 (gmt 0)

10+ Year Member



The code does not work. It is not redirecting example.com to www.example.com or www.example.com/index.html to www.example.com/

riospace

2:48 pm on Oct 22, 2006 (gmt 0)

10+ Year Member



The redirect for non-www to www does work, but I do not think the following code is not working properly:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ [www\.domain\.com...] [R=301,L]

I am a little confussed though, what exactly is this code doing?

jdMorgan

2:57 pm on Oct 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It redirects direct client (browser or robot) requests for /<any-number-of-directories>/index.php, index.html, or index.htm to /<any-number-of-directories>

The code shown is correct, but if you have not done so already, replace the broken pipe "¦" characters with solid pipes from your keyboard (usually Shift-\). Posting on this forum removes some spaces and shows the pipe characters as broken pipes.

Jim

g1smd

3:57 pm on Oct 22, 2006 (gmt 0)

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



The code in message #3130302 should work, as it was taken directly from a live server, and just the domain name replaced.

riospace

9:16 pm on Oct 22, 2006 (gmt 0)

10+ Year Member



Thanks!

Everything seems to be working now. This is what my .htaccess looks like now:

DirectoryIndex index.php index.html index.htm

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?¦php)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?¦php)$ [www\.example\.com...] [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ [www\.example\.com...] [R=301,L]

redirect 301 /index.html http://www.example.com/index.php

Please let me know if anything is out of wack.

g1smd

10:04 pm on Oct 22, 2006 (gmt 0)

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



You don't need this line:

redirect 301 /index.html http://www.example.com/index.php

The extra code you just added already redirects index.php and index.html and index.htm to / in any folder and in the root, and because index.php is the first filename in your DirectoryIndex directive, that content is what will be displayed when you ask for ending / URLs.

riospace

3:39 am on Oct 23, 2006 (gmt 0)

10+ Year Member



RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ [www\.example\.com...] [R=301,L]

When I add the code above, only my homepage shows a Page Rank. What can I do to fix this and why is this happening?

riospace

5:46 am on Oct 24, 2006 (gmt 0)

10+ Year Member



Does anyone know why no page rank is showing up when I use the rewrite code? Also, what would you suggest I do to fix this problem? I do not want to lose search engine results without this redirect, but I really do not want to lose my page rank.

jdMorgan

1:07 pm on Oct 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The simple answer is that PageRank is really assigned to URLs, not pages.

So if you redirect your URLs to other URLs, then it will take anywhere from three to thirty days for the PageRank to be assigned to the new URL.

Like most things related to search engines, there can be no change without pain...

Jim

riospace

1:02 pm on Oct 25, 2006 (gmt 0)

10+ Year Member



It has now been about 2 weeks since I changed my internal links to point to directories instead of files and did not use a redirect.

Would it still be benificial to use the following code eventhough 2 weeks have gone by since the change and since I will loose my page ranks.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ [www\.example\.com...] [R=301,L]

Basically, should I still add this code to my .htaccess file at this time?

g1smd

7:18 pm on Oct 25, 2006 (gmt 0)

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



Yes, add it. It will mop up any PR passed to "index" pages, and transfer most of it to the new "/" URL. It will also stop any new promotion of index pages by people who cut URLs from the browser URL bar and paste them into the content of their site.

riospace

12:10 am on Oct 26, 2006 (gmt 0)

10+ Year Member



Thanks for your help g1smd.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ [www\.example\.com...] [R=301,L]

I noticed that when I inserted the code above into my .htaccess file that a few internal links (that I missed) in my site that still point to website.com/directory/index.html went to error pages when I clicked on them. Why is this happening? I am still trying to figure out the complete function of this code.

jdMorgan

4:21 am on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ http://www.example.com/$1 [R=301,L]

I am still trying to figure out the complete function of this code.

The code means:

-----

IF the broswer makes a request such as

GET /index.htm HTTP/1.1

or

HEAD /apples/oranges/plums/index.php?pear


AND the current requested URL path (which could have been rewrrtten previously) is also

/index.htm

or

/apples/oranges/plums/index.php?pear


THEN redirect those requests to

/

or

/apples/oranges/plums/?pear

respectively.

-----

In order to find out why you are getting an occasional 404, it would be very helpful to view your server error log file as well as your server access log file. The access log will show you the URL that was requested, while the error log will likely show you the file that did not exist. With those two facts, it's usually much easier to figure out the problem.

Jim

riospace

8:24 pm on Oct 26, 2006 (gmt 0)

10+ Year Member



My page rank is starting to appear every once and awhile, again, after adding the following code:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ [www\.domain\.com...] [R=301,L]

I was just curious as to why the page rank is showing up only some of the time? Does this have to do with different data centers?

g1smd

12:45 am on Oct 27, 2006 (gmt 0)

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



You probably have some "pages" where "index.html" has the PR and others where "/" has the PR. It might take a few weeks for things to work themselves out.