Solved

Javascript redirect with a twist

Posted on 2004-04-06
5
444 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

734 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