Greetings
I have been trying and trying to find a script that password protects a dynamically generated CMS page. I'm using sNews CMS and all pages except the main index.php page are all contained in a mysql database. Most scripts say to add one line of code to the top of the page to protect. Sorry, can't do that. These pages don't exist until called out of the database by our browsers.
However, another CMS, textpattern which also uses a database can be protected. Here's the modrewrite theory and how it was done -
How To --
Suppose your website is at
http://example.com and TXP is installed in the root directory and you want to use HTTP authentication to protect the section called ‘protected’ (
http://example.com/protected).
This example assumes your website is hosted on an Apache webserver and that you already have an existing .htpasswd file containing usernames and passwords.
1. Physically create that directory ‘protected’
2. Within that directory ‘protected’, create the following .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*) ../index.php
</IfModule>
AuthType Basic
AuthUserFile /path/on/server/to/.htpasswd
AuthName "Only for registered users"
require valid-user
End How To
Theory Explanation --
When you’re allowed to visit the protected directory (which exists physically on the server), the RewriteRule prevents that physical directory from being shown to the user. Instead it redirects the request to Textpattern’s index.php (which would have happened if that protected directory hadn’t existed physically on the server), so TXP can show the section you really wanted to see.
Normally, sections in TXP don’t have a corresponding physical directory. It is all handled by index.php. To be able to password protect with .htaccess, a physical directory is required, but… when you request a file or directory that physically exists, the default TXP installation will no longer take care of it; instead that real, physical directory/file will be shown by the webserver. The rewrite rule overrides that by saying: even though there is a physical file/directory here, we still want TXP to handle the request. Because that happens after the authentication step, you get what you want: a password protected TXP section.
I tried to get sNews to work with this but no luck. I kept getting redirected to my index.php page and not to the other page I wanted to go to ("protected" folder in this example).
Can anyone see how to do this for sNews. I was told on another forum it can't be done because of how the htaccess file for sNews is written. Here it is --
Any thoughts anyone??
tyee