Welcome Guest, Not a member yet? Register   Sign In
Forbid the site's browsing to anyone but not to me
#1

[eluser]Alhazred[/eluser]
I have to put online a website, but before to allow to anyone to use it, I need to test it online.

During the test I want that anyone will see a "work in progress" page, but I want to be able to use it normally.

I know that I could put a redirect to any view file or controller, but there are a lot, so I was thinking something different, something easier to set and unset.

I can't put a redirect only to the main controller because if in example some one writes
www.website.com/aboutus
he opens the "About us" page and from there he could use the menu to navigate.

I was thinking to put something into the index.php, where any request has to pass, but I don't know if it is possible to modify it to have what I need.

Do you have any suggestion?
#2

[eluser]Alhazred[/eluser]
Just to say what I'm thinking: my idea was to read the $_SERVER['REMOTE_ADDR'] value and according to that decide if it's me or some one else.

Of course my current IP address would be hardcoded and changed manually if needed.
#3

[eluser]TheFuzzy0ne[/eluser]
Do you use an .htaccess file? Here's the code from mine I use for when I put the site into maintenance mode. Hopefully it will help you.

Code:
#RewriteEngine On
#RewriteCond %{REQUEST_URI} !^/maintenance_mode.php
#RewriteCond %{REMOTE_HOST} !^123\.45\.67\.89
#RewriteRule $ /maintenance_mode.php [NC,L]

Just use your own IP address, and make sure you have a file in your Web root called maintenance_mode.php (with a message to your users), then uncomment those lines.
#4

[eluser]Alhazred[/eluser]
Yes, of course I use an .htaccess file, it is very simple at the moment
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|static|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I've added your lines and uncommented them obtaining
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|static|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_URI} !^/maintenance.php
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1
RewriteRule $ /maintenance.php [NC,L]
127.0.0.1 because I'm making a try on my local machine.
I've put a maintenance.php file in the web root.

if I try to access the site it works regularly, I've tried to change the IP address and I obtain an Internal Server Error message.

I've tried to comment my 2 additional lines
RewriteCond $1 !^(index\.php|static|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

in this case:
with 127.0.0.1 I can access the home page, but as I click any link, I got an error because the url is not correctly routed by CI
If I put a different IP into the .htaccess I'm redirected to the maintenance.php page

So, what I have at the moment is:
- I can use the site, but other people gets an error
- other people gets and under maintenance page, but I cant use the site

How do you set your .htaccess to use the website and give the under maintenance page to the users?
#5

[eluser]TheFuzzy0ne[/eluser]
Try this:
Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/maintenance.php
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1
RewriteRule $ /maintenance.php [NC,L]

# If the URL starts with the following, redirect to the index.php.
# This is not necessary if you don't have your application or system directories in your Web root.
RewriteCond %{REQUEST_URI} ^/(system|application)
RewriteRule ^(.*)$ /index.php/$1 [L]

# Check to see if the file or directory exists. If it doesn't, re-route via index.php.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

The order was incorrect, so it was mangling the URL. I've also edited your existing .htaccess data to make it a little more robust.

If that doesn't work, you may need to substitute the IP address with your actual internal IP address. i.e 192.168.0.1, or whatever.
#6

[eluser]Alhazred[/eluser]
Thank you, that works.




Theme © iAndrew 2016 - Forum software by © MyBB