0

I am shutting my website down and I am needing the website to stay live for the next 3 months. What I am wanting to do is basically only let registered users login. The rest of the website will be off limits. How can I set it up to where no matter what page the person goes to, it will always redirect them the "Login" page?

Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
three3
  • 2,756
  • 14
  • 57
  • 85
  • hard to believe you will be able to solve with .htaccess but try to be more specific on what technologies are you using, how the website is structured and if you have some method to check a user is authenticated. – Narcis Radu Jan 30 '12 at 23:33

5 Answers5

1

You could use a simple redirect I suppose:

<?php
header("Location: http://www.example.com/login_page.php");
exit;
?>
Tom
  • 734
  • 2
  • 7
  • 27
0

i'd say it depends on how the entire site is set up. If all the pages have something in common (like a master page in asp), you could place in that master page code something that attempts to check the session state. If the session state doesn't contain some form of authentication (like the kind you use when a user is logged in), then redirect the user to the login page.

Sinaesthetic
  • 11,426
  • 28
  • 107
  • 176
0

Try:

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/login_page.php
RewriteRule ^ /login_page.php [R=301]

Source

Community
  • 1
  • 1
shaunsantacruz
  • 8,903
  • 3
  • 19
  • 19
0

If you are using Apache, you can create a .htaccess file in the root of your website with the following contents.

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule (.*) http://www.yournewwebsite.com.com/login.php [R=301,L]
</IfModule>

However, beware that this file will have an effect on every page on your website - including the login page.

cb1
  • 930
  • 7
  • 16
0

I would suggest you add in a bit of functionality to your current set up, where you can add a login script first.

Example:

<?php
include ("login.php");
if($logged_in === false){
//show login page.
exit();
}
//then rest of code goes here.

This way, your site still has all it's pages, but now you can limit to only people allowed to log in.

Jay D.
  • 672
  • 5
  • 12