Changes

Jump to navigation Jump to search

Old:Basic authentication and redirection

454 bytes added, 01:04, 24 November 2010
no edit summary
<=[http://ecoquvejoz.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=&lt;span id="&quot;top"><&quot;&gt;&lt;/span>&gt;<&lt;div style="&quot;padding:0;margin:0; border-bottom:3px inset #000000">&quot;&gt;
{|
| [[Image:uc_small_logo.gif | MPG UniCenter]] ||
Extending Apache’s basic authentication using mod rewrite.
|}
<&lt;/div>&gt;{| cellpadding="&quot;2"&quot;
|
__TOC__
Uniform Server already has this authentication mechanism in place.
Name-password pairs are stored in the file '''.htpasswd''' located in folder '''<&lt;nowiki>&gt;*<&lt;/nowiki>&gt;\Uniform Server\udrive\htpasswd\www''' it has the default pair '''root:root''' (order name:password)
To enable Uniform Server as a private server open the file '''.htaccess''' contained in folder '''www''' and uncomment the following four lines as shown:
<&lt;pre>&gt;AuthName "&quot;Uniform Server - Server Access"&quot;
AuthType Basic
AuthUserFile /htpasswd/www/.htpasswd
Require valid-user
<&lt;/pre>&gt;
Run the servers, type '''<&lt;nowiki>&gt;http:/localhost<&lt;/nowiki>&gt;''' into your browser address bar and you will be challenged for a user name and password, to gain access enter '''root''' and '''root'''.
The '''htaccess''' file protects the folder it’s contained in and all sub-folders hence if you try to directly access a page anywhere on the server you will be challenged. '''Validation''' is stored meaning you are required to authenticate only once and will not be challenged again.
'''''Note 2'':''' Before continuing restore the above four lines back to their defaults as shown below:
<&lt;pre>&gt;#AuthName "&quot;Uniform Server - Server Access"&quot;
#AuthType Basic
#AuthUserFile /htpasswd/www/.htpasswd
#Require valid-user
<&lt;/pre>&gt;
'''''[[#top | Top]]'''''
## Folder secure contains '''John.html''', '''Dave.html''' and '''Mike.html''' these are the personal data pages.
## This folder also contains an '''index.html''' page which states something like “'''you need to login'''” its a default should the login fail.
<&lt;ol start="&quot;2">&quot;&gt;<&lt;li> &gt; My main index page in the root folder '''www''' contains the following link:<&lt;br>&gt;'''<&lt;nowiki><&gt;&lt;a href="&quot;secure/index.html">&quot;&gt;Secure login<&lt;/a><&gt;&lt;/nowiki>&gt;'''<&lt;br>&gt;When clicked takes me to the protected folder.
<&lt;li> &gt; Open the file '''.htpasswd''' located in folder '''<&lt;nowiki>&gt;*<&lt;/nowiki>&gt;\Uniform Server\udrive\htpasswd\www''' delete its content and add name/password pairs e.g<&lt;pre>&gt;
John:21
Dave Smith:22
Mike:23
<&lt;/pre>&gt;
Use real passwords e.g '''Mst23Xfrs''' (21,22,23 makes it easier to test).
'''''Note'':''' You can use spaces in the name.
<&lt;li> &gt; Copy '''.htaccess''' from the root folder '''www''' to folder '''secure''' (this saves the pain of creating one) once copied open the file delete its contents and add the following:
<&lt;pre>&gt;
AuthUserFile /htpasswd/www/.htpasswd
Require valid-user
RewriteCond %{REMOTE_user} ^Mike$
RewriteRule (.*) /secure/Mike.html [R,L]
<&lt;/pre>&gt;<&lt;/ol>&gt;
*Each page to be protected requires three lines:
:* After a mod rewrite the URL is passed to the rewrite engine and reprocessed. To prevent an infinite loop the first line tests for an individual file, if present it means the URL was processed and the rewrite engine should now perform the actual rewrite.
# Folder ''secure2'' contains three sub-folders '''mpg1''', '''mpg2''' and '''mpg3''' these will be assigned to three users '''Jane''', '''Dawn''' and '''Ruth Smith''' respectively.
# Folder '''secure2''' also contains an '''index.html''' page which states something like “'''you need to login'''” its a default should the login fail.
# My main index page in the root folder '''www''' contains a second login link:<&lt;br>&gt;'''<&lt;nowiki><&gt;&lt;a href="&quot;secure2/index.html">&quot;&gt;Secure login 2<&lt;/a><&gt;&lt;/nowiki>&gt;'''<&lt;br>&gt;When clicked takes me to the protected folder (secure2).<&lt;ol start="&quot;5">&quot;&gt;<&lt;li> &gt; Open the file '''.htpasswd''' located in folder '''<&lt;nowiki>&gt;*<&lt;/nowiki>&gt;\Uniform Server\udrive\htpasswd\www''' and add name/password pairs for our three new users e.g
<&lt;pre>&gt;
John:21
Dave Smith:22
Dawn:42
Ruth Smith:43
<&lt;/pre>&gt;
Use real passwords e.g '''X78Mst23Xfrs''' (41,42,43 makes it easier to test).
'''''Note'':''' Remember as previously stated you can use spaces in names.
<&lt;li> &gt; Copy '''.htaccess''' from the root folder '''www''' to folder '''secure2''' once copied open the file and delete its contents, add the following:
<&lt;pre>&gt;AuthName "&quot;Private area Please Login"&quot;
AuthType Basic
AuthUserFile /htpasswd/www/.htpasswd
RewriteCond %{REMOTE_user} ^Ruth\ Smith$
RewriteRule ^(.*) secure2/mpg3/$1 [R,L]
<&lt;/pre>&gt;<&lt;/ol>&gt;
*Each page to be protected requires three lines:
:* After a mod rewrite the URL is passed to the rewrite engine and reprocessed. To prevent an infinite loop the first line tests for a sub folder name, if present it means the URL was processed and the rewrite engine should now perform the actual rewrite.
322

edits

Navigation menu