Domain Forwarding or URL Redirection


also known as URL Forwarding or Domain Redirection. Its a technique of making webpage available through many URLs.

Checkout wikipedia article on URL redirection for uses of redirection.

In Short,
  • Client Side Fowarding : URL in client browser changes.
  • Server Side Redirection : URL in client browser does NOT change. User remains on same website/domain.
  • Server Side Forwarding or DNS Forwarding : URL in client browser does NOT change. User is moved to NEW website.

All the above methods are explained below in detail. I will be using Ruby on Rails for illustration.

Domain forwarding techniques

Client-Side Redirection

The server sends a 301 or 302 redirect response with a Location: header containing the new URL. The client browser makes another request to the new URL. This is the most common form of domain forwarding.

302 is for temporary redirection. It is used when the requested resource resides temporarily under a different URL. For Example: Latest article at my site are available at www.mysite.com/latest/ which would temporarily redirect to www.mysite/article/356.html and then to www.mysite/article/357.html
1
2
3
4
5
6
7
8
9
10
11
# 302 is default response status of redirect_to
# in controller latest
def index
  redirect_to "article/356"
end


# or redirect to another website
def index
redirect_to "http://www.newsite.com"
end
301 is used for permanent redirection which means that the resource has moved permanently and people should update their information for this URL.
1
2
3
4
def index
  headers["Status"] = "301 Moved Permanently"
  redirect_to "http://www.newsite.com"
end

Server side Redirection
The server transparently rewrites the request URL to another URL. User remains on the same website and the URL on the client browser does not change.
1
2
3
4
5
6
7
8
9
10
##<strong>Two ways</strong>
# 1. Use routes.rb
# in routes.rb write following to redirect incoming request to 'your_controller/create_new'
map.connect 'my_controller/create', :controller => 'your_controller', :action => 'create_new' 

# 2. render :action
# in my_controller
def create
  render :controller => 'your_controller', :action => 'create_new'
end

Server side Forwarding

The server transparently rewrites the requrest URL to another URL. The user is moved to a NEW website and the URL on the client browser does not change. Also known as url masking or url cloaking or url shadowing. The most common method is by Frame Redirects


Note : Apache "core" does NOT perform ANY sort of redirection. Add on modules like mod_redirect to get Client-Side Redirection, mod_rewrite to get Server-Side Redirection, and mod_proxy to get Server-Side Forwarding. So, the ability to redirect is NOT built-in; the modules happen to be in common distros and configuration is baked into httpd.config and .htaccess.

(shamelessly copied from Domain Forwarding in IIS)


DNS Forwarding
The output is exactly similar to Server side Forwarding but approach is different. The user is moved to NEW website and the URL on the client browser does not change. You need to set appropiate CNAME entry in your domainname record at your DNS server. Many hosting service providers or registrars provide you with this service by the name 'Domainname forwarding'. If you have your own DNS server, you can easily set CNAME entry. For example :

1
2
3
4
; my website is www.mysite.com. I want to redirect blog.mysite.com to www.myblog.com
; I will add following record in the DNS setting of www.mysite.com
blog       IN      CNAME  www.myblog.com.
; NOTE : do not forget to put '.' in the end
For detailed information about CNAME, please refer to Canonical Name Record (CNAME)


References
Filed in ruby on rails
Tagged as  
Posted on 25 August
4 comment Bookmark   AddThis Social Bookmark Button Updated on 09 September
Comments

Leave a response

  1. tanzaniteAugust 01, 2008 @ 04:21 AM

    I love the way the code is so easy to understand for redirects. It doesn’t get any easier than redirect_to as a command!

  2. Rick LimAugust 23, 2008 @ 01:54 PM

    Thanks for this tutorial. I had been wondering how to do that until i read this.

  3. bruunhauseAugust 29, 2008 @ 06:17 AM

    Just wanted to drop a quick note: Great tutorial, recommended.

  4. TanzaniteSeptember 05, 2008 @ 10:46 PM

    The important thing to note is that 301 should always be used instead of 302 in the case where redirects need to retain previous properties, in the case of rankings.