HTTP Forward using path variable with JavaScript

Written by - 0 comments

Published on - Listed in Internet


HTTP Forwards are being used a lot. And it's even very easy to use the actual path if your domain or URL has changed for example.
So let's say you are using a free hoster and you want to forward your webpages to another domain: http://username.mywebhost.bla/files/page1.html -> has to be pointed to http://www.mydomain.info/files/page1.html Note that only the domain name changes. The problem in this situation was, that mod_rewrite and PHP is not activated on the free hoster server (username.mywebhost.bla). So we have to find another solution.

Instead of changing each page of the website and set a meta forwarding to the new URL (this could take a while depending on the size of your website!) there is still the ability to use a JavaScript code. You can let JavaScript make the output of the meta forwarding, altogether with the actual path. This looks like this:

<script language='javascript'>
var path = location.pathname;
document.write("<meta http-equiv='Refresh' content='0; url=http://www.mydomain.info"+ path +"'>");
</script>

Place this into your HTML HEAD section and it works. JavaScript MUST be enabled in the browser of course but still, you get a nice and working dynamic forward even when you can't use PHP or .htacces Rewrite Rules.


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   OpenSearch   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder