Wednesday, June 22, 2011

URL redirection with masking

Here is how to redirect a domain with masking the URL


For ex: 
We need to redirect the domain "abc.com" to "xyz.com". If  we redirect the domain using htaccess redirection using the code below 



RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/www\.xyz\.com" [L]


When we access the domain "abc.com" it will redirect to "xyz.com" but the address bar shows "xyz.com" only not 'abc.com".


so we need to mask the "xyz.com" domain name using the script below.


You need to add the below code in the "index.html" file of the domain in which you are going to add redirect.


#root@test[~] vi index.html


<html>


<head>

<title>Same Title As Your Homepage</title>
<!--incase they have javascript turned off-->

<script type="text/javascript">
<!--changes title bar to match title on current page in frame-->
function changeTitle()
   {
   if (top.frames['main'].document.title)
      {
      top.document.title=top.frames['main'].document.title;
      }
   }
</script>
</head>


<frameset>
<frame name="main"
src="http://xyz.com"scrolling="auto"
target="main" ONLOAD="changeTitle();">
<!--You need the onload handler to make the javascript work-->

<noframes>

<body>
Place a suitable message here for people with browsers that can't read
frames.
</body>

</noframes>

</frameset>

</html>

In this scenario we are redirecting the domain to "xyz.com" so I have given the 
URL like that.

Now if you access the domain "abc.com" it will display the page of the "xyz.com" but the URL in the address will be "abc.com".