Tuesday, July 12, 2011

Common ways to redirect website

However there are many ways to redirect website's but here are simple ways by examples, This question often comes in-front of you when giving interview for web designer or developer.

For this example I will use the website:
Let’s say this site is build in the folder: /folder/ we need a redirect from

META Tags:
Create in the root of your domain an index.html and use a meta-refresh tag in the of your HTML.
This way of redirecting is according to W3C not so nice, and it also will have a delay.
You can set this delay, however I set it to 0.

<meta http-equiv="refresh" content="0;URL=" />

Link :
Not so nice, but to most accessible way, is to just create an empty index.html with an hyperlink
to your new folder.
<a href="">Your link</a>.

Javascript :
A good way to use. However if Javascript is disabled in your browser your stuck on the page where this
Javascript code is placed. (index.html in the root of your domain)

<script type="text/javascript">

Server side :
This will work on Apache linux servers only.
Create with notepad a file called: .htaccess with the below content. Place this file in root of your domain.
Please note that on some servers you can not see this file with your FTP client. I found out that most of the time the webvariant of your hosted server (file manager), will show them.
However, I think this is the best and fastest way of redirecting.

RewriteEngine on

rewriterule ^(.*)$$1 [r=301,nc]

No comments:

Post a Comment