Forum Moderators: phranque

Message Too Old, No Replies

Efficient rewrite w/o losing the pagerank

         

new_b

12:53 pm on Sep 24, 2010 (gmt 0)

10+ Year Member



I've migrated a 'conventional' html website to the WordPress. I want to preserve the page ranks for the google indexed pages of the old site.

However all the old links are with .shtml extension compared to the new WP URL, otherwise everything in the URL is the same for old and new sites.

So I planed is a rewrite to achieve the following result.

OLD URL: http://example.com/my-page.shtml
NEW URL:http://example.com/my-page

The htaccess code is

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


My question is,

is this the efficient (from ranking & server point ) code to achieve the result I mentioned.
Or is there a better/smarter way to achieve this.....

jdMorgan

2:25 pm on Sep 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code is incorrect, because the 'file extension' in the RewriteRule pattern won't match ".shtml".

You can also improve the efficiency a little bit:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(([^/?#\ ]+/)*[^.?#\ ]+)\.shtml\ HTTP/
RewriteRule \.shtml$ http://www.example.com/%1/ [R=301,L]

mod_rewrite is very compact and efficient -- Certainly more so that any scripted method. If you can put this code into a <Directory> container in a server config file, then it will be even more efficient.

Jim

new_b

6:53 pm on Sep 24, 2010 (gmt 0)

10+ Year Member



I'm on a shared hosing. So i'm afraid that I can get access to a server config file. I've to manage with htaccess. Hope this will not make a dent on the performance/pagerank

Jim...your code worked like a charm! thank you once again :)