Header RSS Feed
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

HTTP Forward using path variable with JavaScript
Monday - Feb 22nd 2010 - by - (0 comments)

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

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.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6938 Days
until Death of Computers