Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-21-2009, 08:32 PM   PM User | #1
martinrab
New Coder

 
Join Date: Jan 2009
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
martinrab is an unknown quantity at this point
Redirect ALL visitors ALWAYS to index.html

Hi,

I am just starting to understand JAVA Script a little bit to the point where I am able to modify scripts. Thing is now I can't find anything similar to what I need to modify

So maybe someone here can help me with the following:

I have a page which can be found in google which is nice. But people can find a lot of sub-pages as well which is nice from a PR point of view. Nevertheless I don't want people to jump in the middle. I want them all to start on index.hmtl and nowhere else. So is it possible to have all visitors who click on a search result for example in google to be redirected to index.html ? Maybe referrer based redirect? Can someone help me out on how this is done?

Thanks in advance. Martin
martinrab is offline   Reply With Quote
Old 01-21-2009, 10:22 PM   PM User | #2
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,544
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
Although you can do it with js its better to do this on the serverside.

Provided you have php running on your server
(and most do), then rename your pages to .php pages

Now you can use sessions.

Add this to all the non-index pages:

PHP Code:
<?php 
@session_start();

if (@
$_SESSION['auth'] != "yes" ){
     
header("Location: index.php");
     exit();
}  
// end if
?>
then on the index page add:

PHP Code:
<?php 
@session_start();
$_SESSION['auth'] = "yes";
?>
Of course all your internal links need to be changed to .php as well
no .htm ot .html can stay - all .php

OK
jeddi is offline   Reply With Quote
Users who have thanked jeddi for this post:
martinrab (01-22-2009)
Old 01-21-2009, 10:25 PM   PM User | #3
jeddi
Senior Coder

 
Join Date: May 2006
Posts: 1,544
Thanks: 26
Thanked 4 Times in 4 Posts
jeddi has a little shameless behaviour in the past
If you don't want to do the php route
you can use mod_rewrite rules in your htaccess file.

But the php route is easier and quicker.
jeddi is offline   Reply With Quote
Old 01-22-2009, 09:39 AM   PM User | #4
martinrab
New Coder

 
Join Date: Jan 2009
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
martinrab is an unknown quantity at this point
Hey Jeddi,

thanks for your reply. I am in way over my head already I guess. For PHP hoes the same as for Java Script as far as I am concerned. I can read the code and modify it but don't really understand it yet. So you are saying that if I rename my fiels to *.php and paste your code in there "as is" all funcitonality will be the same as in my original html files but people are redirected to index? Will try right now! You are a champion!
martinrab is offline   Reply With Quote
Old 01-22-2009, 10:39 AM   PM User | #5
martinrab
New Coder

 
Join Date: Jan 2009
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
martinrab is an unknown quantity at this point
Hey Jeddi, your second name is not by coincidence "GOD"? If not you are to me. What a cool solution. This actually now by coincidence solved another problem I had on the way..... THANKS THANKS THANKS!
martinrab is offline   Reply With Quote
Reply

Bookmarks

Tags
java script, redirect to index.html

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:10 AM.


Advertisement
Log in to turn off these ads.