html - Redirect based on query string -


i'm hosting things on home server, ip address changes. don't have domain name, can't give people bookmark. fix this, made small perl script spits out html file dropbox, can let people bookmark that. know, that's not best solution, seems working far.

the issue is, i'd make nicer. want have optional query string, ?path=wiki or something, , when loads that, it'll automatically redirect http://(my_ip)/wiki

unfortunately don't know how make redirect happen, , haven't seen who's got answer. optional, dynamic 1 that, although should simple if understand right.

purely in html don't see happening

but javascript, if anyhow spit out custom html page, replace ipadres of targeturl in example below

<!doctype html> <html> <head>   <title>test redirect</title>   <script type="text/javascript">   var targeturl = 'http://127.0.0.1';    function querystring(paramname) {     var url = document.location.href, params, param, i, reply = {}, name, value;     if (url.indexof('?') < 0) {       return null;     }     params = url.split('?')[1].split('&');     (i = 0; < params.length; i++) {       param = params[i].split('=');       name = (param[0] || '').tolowercase();       value = param[1] || '';       if (typeof paramname === 'undefined' || paramname.tolowercase() === name) {         if (typeof reply[name] !== 'undefined') {           if (typeof reply[name] === 'string') {             reply[name] = [ reply[name], value ];           } else {             reply[name].push(value);           }           continue;         }         reply[name] = value;       }     }     return reply;   }    function redirect() {    var path = querystring('path');    if (path === null || typeof path.path === 'undefined' || typeof path.path !== 'string')     {     document.location.href = targeturl;    } else {     document.location.href = targeturl + '/' + path.path;    }   }   </script> </head> <body onload="javascript:redirect()"> <h1>redirecting homesite</h1> <p>you being redirected, please wait while page loading!</p> </body> </html> 

in case, if querystring parameter of ?path=wiki there, redirect targeturl , add path /wiki it

update

update use hyenahome.html#path:wiki rather hyenahome.html?path=wiki

<!doctype html> <html> <head>   <title>test redirect</title>   <script type="text/javascript">   var targeturl = 'http://127.0.0.1';    function querystring(paramname) {     var url = document.location.href, params, param, i, reply = {}, name, value;     if (url.indexof('#') < 0) {       return null;     }     params = url.split('#')[1].split('&');     (i = 0; < params.length; i++) {       param = params[i].split(':');       name = (param[0] || '').tolowercase();       value = param[1] || '';       if (typeof paramname === 'undefined' || paramname.tolowercase() === name) {         if (typeof reply[name] !== 'undefined') {           if (typeof reply[name] === 'string') {             reply[name] = [ reply[name], value ];           } else {             reply[name].push(value);           }           continue;         }         reply[name] = value;       }     }     return reply;   }    function redirect() {    var path = querystring('path');    if (path === null || typeof path.path === 'undefined' || typeof path.path !== 'string')     {     return;    } else {     document.location.href = targeturl + '/' + path.path;    }   }   </script> </head> <body onload="javascript:redirect()"> <h1>redirecting homesite</h1> <p>you being redirected, please wait while page loading!</p> </body> </html> 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -