Solved

Javascript redirect with a twist

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML Video won't Autoplay on site 6 30
query of query sort 6 106
two submit buttons one form 15 97
Grunt script for Build Process 1 42
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

807 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