Skip to content Skip to sidebar Skip to footer

Url Redirection

I am trying to achieve something like, that is on the below link. http://www.laterooms.com/ This website is at the above URL. But even if you type .co.uk or .net or .org Like

Solution 1:

First of all, you should be in possession of the other domains (with the extensions you want). Then you can either use javascript to set top.location.href='http://your.address.com/' or use other means, like setting up your web server to redirect the requests, or your domain name registrar.

Solution 2:

You can either use different techniques on server side to force a redirect, or you can send a page containing a redirect Refresh: 0; url=http://www.example.com/

Wikipedia has a good overview on this.

<head><metahttp-equiv="refresh"content="5; URL=http://de.selfhtml.org/"></head>

Solution 3:

If you own/have possession of those other domains..

You could set forwarding (dns settings) for each of the domains you wish to redirect to the primary domain.

That would get you away from having to code a page for each one of those domains.

Much cleaner, and easier.

Solution 4:

Assuming you own all the domains, and they all point to the same webserver, then this code should do it;

var href_parts = top.location.href.split('/');
  if (href_parts[2] != 'www.laterooms.com') {
      href_parts[2] = 'www.laterooms.com';
      top.location.href = href_parts.join('/');        
  }

Basically -- have javascript test what domain you currently are on, and if not on the .com then update the URL and store it back into the location.href for the page which will automatically trigger a page-reload with the new URL.

The above code preserve the URL path within the domain, so if somebody types in

   http://www.lateroom.co.uk/mypath/here

will redirect to

  http://www.lateroom.com/mypath/here

If you don't want to preserve the path /mypath/here then the code will be sligthly simpler as you can just hardcode the destination path rather than using the join

Post a Comment for "Url Redirection"