Solved

Javascript redirect with a twist

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Migrating to Exchange 2013 4 54
removing hyperlinks from end-notes in a PDF to HTML conversion 8 121
WCAG audit tools 1 106
Animated .jpg? 13 104
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

730 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