how to redirect one url to another

So a few days ago, the stumbleupon community attacked my site like a swarm of wasps chasing the guy who kicked a football in to their nest 🙂

Not surprisingly, my site was overpowered and eventually died from stress… the site was unprepared and had never experienced such a vicious, unprovoked attack like this before.

So whilst i tried to resurrect the site from the dead, i didn’t want people seeing a big ugly ‘access denied’ or ‘please contact the admin’ message appearing. I needed something to cover up the body and give us some privacy as we worked to bring things back to life.

One line in a .htaccess file was that ‘something’. A typical wordpress .htaccess file might look like this;

Options +FollowSymlinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www.|$) [NC]

RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

SecFilterEngine Off

SecFilterScanPOST Off

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

# END WordPress

So let’s say you’re experiencing a similar ‘attack’ on your site… thousands of visitors from stumbleupon or digg or wherever… there doesn’t seem to be and end in sight… you may be on a shared host… the safest way to protect yourself and your site from going down is by writing a plain html version of your post…

Just like i done here. It’s better than nothing at all, plus you can let people know what’s happening. You simply add this line of code anywhere in your .htaccess file;

redirect temp oldarticle newarticle

So mine would be;

redirect temp /21-cool-webmaster-resources http://www.smemon.com/creamed.html

And my new .htaccess file would look like this;

Options +FollowSymlinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www.|$) [NC]

RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

redirect temp /21-cool-webmaster-resources http://www.smemon.com/creamed.html

SecFilterEngine Off

SecFilterScanPOST Off

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

# END WordPress

That’s it! One line of code which could save your site from dying! Here’s some more tips and tricks you can mess around with using .htaccess.

2 thoughts on “how to redirect one url to another”

Leave a Reply