How to tell search engines if page has been moved


If you ever want to restructure your site, one of the biggest issue is the already established inlinks and search engine rankings. You do not want to lose those, under any circumstances, but this does not mean you cannot move your pages.

When a user requests a page, their browser sends the request to your server. Your server will return a status code – this status code is 200 for a normal page. You may have also heard of 404, used for a non-existant page. You can redirect your users with a 302 redirect – this is a temporarily moved page, or a 301 redirect – a permanently moved page.

This code should be placed in the htaccess file in the root of your domain, i.e. domain.com/.htaccess

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /
   RewriteRule ^moved/page.html$ newlocation/page.html [R=301,L]
</IfModule>

 

You may wish to redirect pages depending on the QUERY STRING, for instance if you convert your forum to a new software. Let’s assume your old topic view page was viewtopic.php?t=346 and the new page is showthread.php?tid=346. As mentioned in the tutorial, the query string is not passed to the RewriteRule so we must introduce a RewriteCond:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /
   RewriteCond %{QUERY_STRING} t=([0-9]+)
   RewriteRule ^viewtopic.php$ showthread.php?tid=%1 [R=301,L,QSA]
</IfModule>

Note the use of the QSA flag so that we keep any additional GET parameters.

source:easymodrewrite.com

One comment

  1. Coltin says:

    Keep it coming, wrtires, this is good stuff.

Leave a Reply to Coltin Cancel reply

Your email address will not be published. Required fields are marked *