Redirecting web sites using htaccess

Recently I decided to consolidate several of my websites, which I had been ignoring in to one easy to ignore website. The first step was to add the content from the soon to be defunct web sites to this one and then finally set up my redirects.

In Apache this is done using a module called mod_rewrite and a hidden configuration file called .htaccess in which I needed to redirect permanently several pages directly to the equivalent pages on this site and redirect everything else except the administration pages to a category on this site.

So if a visitor went to http://conkybots.net/2014/03/24/weatherbot-three-hour-forecast/ then they would end up on http://www.thefifthcontinent.com/2014/08/weatherbot-three-hour-forecast/ otherwise they would end up on http://www.thefifthcontinent.com/category/conkybots/. The solution took a bit of experimenting but was actually incredibly simple.

Options +FollowSymLinks
RewriteEngine on

Make sure that the rewrite engine is active.

Redirect 301 /2014/03/24/weatherbot-three-hour-forecast/ http://www.thefifthcontinent.com/2014/08/weatherbot-three-hour-forecast/ 
Redirect 301 /2014/03/22/107/ http://www.thefifthcontinent.com/2014/08/weatherbot-variables-current-conditions/
Redirect 301 /2014/02/16/quick-start-guide/ http://www.thefifthcontinent.com/2014/08/quick-start-guide/

These are the specific pages to redirect to the new site

RewriteCond %{REQUEST_URI} !/wp-admin [NC]
RewriteCond %{REQUEST_URI} !/2014/03/24/weatherbot-three-hour-forecast/ [NC]
RewriteCond %{REQUEST_URI} !/2014/03/22/107/ [NC]
RewriteCond %{REQUEST_URI} !/2014/02/16/quick-start-guide/ [NC]
RewriteCond %{HTTP_HOST} ^conkybots.net [NC]
RewriteRule ^(.*)$ http://www.thefifthcontinent.com/category/conkybots/ [L,R=301,NC]

Redirect everything else but ignore the pages already handled by the redirects. And of course ignore the admin.

Leave a Reply

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

*