views:

258

answers:

2

In one of the page I have is where administrators are allowed, however, I use if the session isn't set, the header will redirect them to index.php and that method works.

If I replace index.php with home which is for the htaccess which changes it to index.php but it gives an error in the browser

This works:

if(!isset($_SESSION['MEMBER'])){ header("Location: index.php"); }

This does not work:

if(!isset($_SESSION['MEMBER'])){ header("Location: home"); }

htaccess:

RewriteRule ^home$ index.php

The error in Firefox:

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

This problem can sometimes be caused by disabling or refusing to accept cookies.

What's wrong with it? How do I get this method to work?

+1  A: 

You're redirecting index.php to home in your php file, and home to index.php in .htaccess. Firefox is telling you there is an infinite redirect loop.

Edit: index.php and home are the same thing, so redirecting to either will result in an infinite loop. You need to do something like this:

#.htaccess
RewriteRule ^home$ index.php        # public page
RewriteRule ^members$ members.php   # member only page

And then in index.php

# index.php
if(isset($_SESSION['MEMBER'])){
    header("Location: members");
    exit;
}
Rob
So I cannot use the 'home' in the php header?
YouBook
You can, you just cannot redirect back to itself.
Rob
@Wayne: You can use `home` in the PHP header, but make sure to change the value of `$_SESSION['MEMBER']` to prevent an infinite loop.
Dor
A: 

You've created an infinite loop. When PHP executes the following code:

if(!isset($_SESSION['MEMBER'])){ header("Location: home"); }

It redirects the browser to /home. But in .htaccess you rewrite the URL to /index.php. Which then again makes PHP to execute the above PHP code.

Dor