Solved

Javascript redirect with a twist

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now