Redirect based on the URL using JavaScript


There are many methods out there to do such a task, it seem many PHP solutions for this and also some JavaScript functions to do this, but they all seem overkill in terms of what’s required to be changes for each redirect.

here is a script with minimal changes required to get it working, this solution is based on the ever popular JavaScript.

A perfect example of using a script like this is if you are trying to target a particular market, for example. I am based in Australia, and I have a domain, and a .com domain. I might have a different offering or market to what I offer in Australia, so with that said I have 1 website but with multiple alias’s and pages for different markets. I need to somehow separate these with the URL, as tells me AU, .com tells me global.

So how do you use the below script easy:



to your domain (without the www) and folder location


Change this to be your location you wish to redirect to

this is the second URL you want it to redirect too.



<script language="javascript">



    var href = document.location.href;


    if (href.indexOf("") > 0) 

        document.location.href =""


        document.location.href =""






Leave a Reply