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 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="+ path +"'>");

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.