views:

98

answers:

3

I've been stuck for a while now on how to create a "Coming Soon" page for my CakePHP site. I need to keep the webroot directory protected via .htpasswd so only authorised users can access the site whilst it's being built. However, regular visitors should be shown the "Coming Soon" page when they visit thesiteurl.com or thesiteurl.com/index.html. All authorised users will gain access to the rest of the site by visiting thesiteurl.com/index.php and entering the login credentials.

Here's the directory structure of the relevant files I think I need to edit to make this work.

/.htaccess
/comingsoon - directory containing images, css and js for the coming soon page
/index.html - the "Coming Soon" page
/index.php - the page authorised users use to access the site
/webroot/.htaccess
/webroot/index.php

Contents of .htaccess

DirectoryIndex index.html

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !/
    RewriteCond %{REQUEST_URI} !/index\.html
    RewriteRule ^$ webroot/ [L]
    RewriteRule (.*) webroot/$1 [L]
</IfModule>

Contents of webroot/.htaccess

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/my/.htpasswd
AuthGroupFile /dev/null
require valid-user

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

These .htaccess rules just take me to the webroot directory file listing if I try to access thesiteurl.com and a blank page styled like the rest of my site if I access thesiteurl.com/index.html. thesiteurl.com/index.php will take me to the index page authorised users see once they log in however.

Any help would be much appreciated.

A: 

Why not setup a separate url for the testing?

test.thesiteurl.com

Then on the main url, you can put a static index.html without jumping through all the hoops. This will allow those who need access the ability to get to the location they need to. Those who are "outside looking in" will visit the main site and see the "Coming Soon".

Far to often we try to merge a development site with the production site like you are trying here. It doesn't make sense to jump through all the hoops. Just because it CAN be done the way you are suggesting, does not me you SHOULD do it this way. K.I.S.S. is always the best option. Keep it as simple as possible. Don't waste your valuable time trying to figure out cool fandangoed ways of doing things. Especially if it will just be thrown away down the road.

cdburgess
I did think about using a subdomain for the main site. However, let's say that for various reasons I can't use a subdomain in this particular example. How would I then go about solving my original problem?
greenie
Quite honestly, I wouldn't. If I couldn't readily figure it out, I wouldn't waste my time. The problem is you are trying to make one site do two different things. However, if you want an easy way to do this, just drop an INDEX.HTML file in WEBROOT. It should override the .php file. Then all the people who actually need access to the cake app can point to `themainurl.com/index.php` and it should work.
cdburgess
A: 

Well here is the issue. http://yoursite.com automatically goes to the webroot directory. You have your index.html file one level above the webroot which cannot be accessed. What you need to do is the following.

/webroot
    /beta - directory containing all beta site pages
        .htaccess - Contains your restricted area code
        index.php - the page authorised users use to access the site
    .htaccess
    index.html - the "Coming Soon" page

Then when you want to view your temp site go to http://yoursite.com/beta. /Webroot is the folder where your website files are stored. Right now you only have the restricted area files in the webroot which is all apache (or w/e you are using) can see. Alternatively you can move your files into webroot folder but my way makes it so users do not have to "attempt" to login to see a coming soon page. I know when I go to a site and it asks me to login without telling me anything, i think the developer has no idea what is going on and that his site is broken and usually will not return. My method only prompts for login should they go to your /beta directory.

jostster
+2  A: 

The cake way would be to put the public access files into app/views/pages.

  1. Set up auth (it's easy and if you haven't already learnt it, you'll need to sooner or later) to give login access to controller functions. See http://book.cakephp.org/view/172/Authentication

  2. If you haven't done it already, copy the pages controller from cake/libs/controller into app/controllers. Make sure that the before filter in PagesController reads something like:

    function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allowedActions = array('display');
    }
    

    See http://book.cakephp.org/view/854/The-Pages-Controller

  3. Clean that htaccess hocus back to what was delivered with cake - it's only going to cause you problems later.

Leo
Also, the guide I used (dated now) was by Chris Hartjes - just google 'chris hartjes authorisation'.
Leo