mod rewrite - Redirect

Apache's Mod Rewrite module is a fantastic way to re-direct web pages that have been moved or renamed. Since September 23rd, 2002, when I re-designed this entire website, I was desperate to find an easier solution to re-direct my readers (linked off Search Engines to old URLs) to the correct pages.

The problem

Just to help illustrate how you could use this information let's assume we had 3 web pages:

http://www.desilva.biz/wd_010427.php
http://www.desilva.biz/grafix_index.php
http://www.desilva.biz/hw_010506.php

and we want to re-direct our readers visiting each page above to their new versions at:

http://www.desilva.biz/refresh.html
http://www.desilva.biz/grafix.html
http://www.desilva.biz/cpuspeed.html

Create or edit the .htaccess file

Either create or open up the existing .htaccess file in your WWW root. i.e
path: /home/username/public_html
Now add the following lines of 'rewrite rules':

code:
RewriteEngine on
RewriteRule ^wd_010427\.php$ refresh.html [R=301,L]
RewriteRule ^grafix_index\.php$ grafix.html [R=301,L]
RewriteRule ^hw_010506\.php$ cpuspeed.html [R=301,L]

Now anybody surfing to your old pages will be automatically and instantaneously re-directed to the new URL! It gets better, the reader will see that the page has been moved since the browser's address bar will show the new URL instead of the one the user typed in.

The REAL power of Apache's mod re-rewrite module

By the way, that's just the 'tip of the iceberg' when it comes to the uses of Apache's mod re-write module. I have successfully set up nearly ALL my webpages including GIDForums™ to use it one way or another so I can link to the pages without having to resort to query strings!

TOP

Do you find it easy to navigate through this site?

 Yes

 No

 Where am I?