0

How do I create a URL redirect page as a HTML file, for example, if it was like http://warrenwoodhouse.webs.com/url/?url=linkgoeshere, as I need it for my page on my website.

The page, when visiting it without a link at the end as http://warrenwoodhouse.webs.com/url/?url= will not redirect to anything, where as with a link such as http://warrenwoodhouse.webs.com/url/?url=http://youtube.com/user/warrenwoodhouse will redirect to the specified page in the URL.

If anyone knows the code for HTML and JavaScript, please feel free to leave a comment below.

2 Answers2

3

I think this can do what you want (found here) :

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

var redirectUrl = getParameterByName('url');
if(redirectUrl != null){
     window.location.href = redirectUrl;
}
Community
  • 1
  • 1
Ugo T.
  • 1,068
  • 8
  • 12
  • Thanks. I'll give it a try and see if it works. How do I add this in to my site since my site is HTML? – warrenwoodhouse Jul 16 '16 at 21:58
  • Look into the script element. – evolutionxbox Jul 16 '16 at 22:00
  • Actually, you've pretty much answered my question here. Thanks dude, you're a star. Here's your example: `http://warrenwoodhouse.webs.com/url/ugot.html?url=http://warrenwoodhouseminecraft.blogspot.com/` which basically redirects the URL page to the blog specified, in this case, my Minecraft Projects blog. – warrenwoodhouse Jul 16 '16 at 22:03
0

Try this:-

    function getParameterByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    }
    var URL = getParameterByName('url');
window.location.href = URL;
Vivek Pratap Singh
  • 9,326
  • 5
  • 21
  • 34