Solved

Javascript redirect with a twist

Posted on 2004-04-06
5
450 Views
Last Modified: 2010-04-06
Hi,

I have my redirect script that automatically takes someone from the current page to another website:

<head>
</head>
<body>
<script language="JavaScript"><!--
        location.href = 'http://xxx.xxx.xxx.xxx/';
//--></script>
<noscript>
Your browser does not support JavaScript, or JavaScript is disabled.
</noscript>
</body>
</html>

However, this assumes that everyone is going to connect to my site using just http://FQDN and not http://FQDN/diflocation/difpage.html. If they do that then diflocation/difpage.html doesn't exist on my webserver, it exists on the webserver I'm redirecting to. How can I redirect to diflocation/difpage.html. I need it to point any of the available files being server by the last webserver.

Thanks
0
Comment
Question by:aabedi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:dorward
ID: 10764879
You would have to generate an HTML document to send to the user with a dynamically generated URI in the middle of the JavaScript (or you could read the URI from document.location - but you would still need to have a page at the URI).

I would suggest not using JavaScript to perform redirects and instead use a real http redirect.

How you do this depends on your webserver. In Apache, for instance, it is just a matter of putting:

Redirect permanent / http://www.example.com/

- and that even redirects /foo to http://www.example.com/foo
0
 

Author Comment

by:aabedi
ID: 10764925
Dorward, yep I'm using Apache... I'm guessing I'd put this bit in my httpd.conf file in my virtual domain configuration (I'm trying to do this for multiple virtual domains)?

Thanks

Ali
0
 
LVL 17

Accepted Solution

by:
dorward earned 250 total points
ID: 10764966
I believe that should work, I've only used it in a .htaccess file myself.
0
 

Author Comment

by:aabedi
ID: 10765315
Dorward, it worked a dream... points are yours!!!
0
 
LVL 17

Expert Comment

by:dorward
ID: 10765328
Thanks!

(Extra benefit - search engines understand http redirects)
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question