Old:Basic authentication and redirection: Difference between revisions

Jump to navigation Jump to search
no edit summary
mNo edit summary
No edit summary
Line 1: Line 1:
<span id="top"></span>
=[http://ecoquvejoz.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
<div style="padding:0;margin:0; border-bottom:3px inset #000000">
&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]] ||
| [[Image:uc_small_logo.gif | MPG UniCenter]] ||
Extending Apache’s basic authentication using mod rewrite.  
Extending Apache’s basic authentication using mod rewrite.  
|}
|}
</div>
&lt;/div&gt;
{| cellpadding="2"
{| cellpadding=&quot;2&quot;
|
|
__TOC__
__TOC__
Line 19: Line 20:
Uniform Server already has this authentication mechanism in place.
Uniform Server already has this authentication mechanism in place.


Name-password pairs are stored in the file '''.htpasswd''' located in folder '''<nowiki>*</nowiki>\Uniform Server\udrive\htpasswd\www''' it has the default pair '''root:root''' (order name:password)
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:
To enable Uniform Server as a private server open the file '''.htaccess''' contained in folder '''www''' and uncomment the following four lines as shown:


<pre>
&lt;pre&gt;
AuthName "Uniform Server - Server Access"
AuthName &quot;Uniform Server - Server Access&quot;
AuthType Basic
AuthType Basic
AuthUserFile /htpasswd/www/.htpasswd
AuthUserFile /htpasswd/www/.htpasswd
Require valid-user
Require valid-user
</pre>
&lt;/pre&gt;


Run the servers, type '''<nowiki>http:/localhost</nowiki>''' into your browser address bar and you will be challenged for a user name and password, to gain access enter '''root''' and '''root'''.
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.
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.
Line 39: Line 40:


'''''Note 2'':''' Before continuing restore the above four lines back to their defaults as shown below:
'''''Note 2'':''' Before continuing restore the above four lines back to their defaults as shown below:
<pre>
&lt;pre&gt;
#AuthName "Uniform Server - Server Access"
#AuthName &quot;Uniform Server - Server Access&quot;
#AuthType Basic
#AuthType Basic
#AuthUserFile /htpasswd/www/.htpasswd
#AuthUserFile /htpasswd/www/.htpasswd
#Require valid-user
#Require valid-user
</pre>
&lt;/pre&gt;


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
Line 58: Line 59:
## Folder secure contains '''John.html''', '''Dave.html''' and '''Mike.html''' these are the personal data pages.
## 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.
## This folder also contains an '''index.html''' page which states something like “'''you need to login'''” its a default should the login fail.
<ol start="2">
&lt;ol start=&quot;2&quot;&gt;
<li> My main index page in the root folder '''www''' contains the following link:<br>'''<nowiki><a href="secure/index.html">Secure login</a></nowiki>'''<br>When clicked takes me to the protected folder.
&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.


<li> Open the file '''.htpasswd''' located in folder '''<nowiki>*</nowiki>\Uniform Server\udrive\htpasswd\www''' delete its content and add name/password pairs e.g
&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
<pre>
&lt;pre&gt;
John:21
John:21
Dave Smith:22
Dave Smith:22
Mike:23
Mike:23
</pre>
&lt;/pre&gt;


Use real passwords e.g '''Mst23Xfrs''' (21,22,23 makes it easier to test).
Use real passwords e.g '''Mst23Xfrs''' (21,22,23 makes it easier to test).
Line 72: Line 73:
'''''Note'':''' You can use spaces in the name.
'''''Note'':''' You can use spaces in the name.


<li> 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;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:


<pre>
&lt;pre&gt;
AuthUserFile /htpasswd/www/.htpasswd
AuthUserFile /htpasswd/www/.htpasswd
Require valid-user
Require valid-user
Line 94: Line 95:
RewriteCond %{REMOTE_user} ^Mike$
RewriteCond %{REMOTE_user} ^Mike$
RewriteRule (.*) /secure/Mike.html [R,L]
RewriteRule (.*) /secure/Mike.html [R,L]
</pre>
&lt;/pre&gt;
</ol>
&lt;/ol&gt;
*Each page to be protected requires three lines:
*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.
:* 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.
Line 122: Line 123:
# 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'' 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.
# 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:<br>'''<nowiki><a href="secure2/index.html">Secure login 2</a></nowiki>'''<br>When clicked takes me to the protected folder (secure2).
# 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).
<ol start="5">
&lt;ol start=&quot;5&quot;&gt;
<li> Open the file '''.htpasswd''' located in folder '''<nowiki>*</nowiki>\Uniform Server\udrive\htpasswd\www''' and add name/password pairs for our three new users e.g
&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


<pre>
&lt;pre&gt;
John:21
John:21
Dave Smith:22
Dave Smith:22
Line 133: Line 134:
Dawn:42
Dawn:42
Ruth Smith:43
Ruth Smith:43
</pre>
&lt;/pre&gt;


Use real passwords e.g '''X78Mst23Xfrs''' (41,42,43 makes it easier to test).
Use real passwords e.g '''X78Mst23Xfrs''' (41,42,43 makes it easier to test).
Line 139: Line 140:
'''''Note'':''' Remember as previously stated you can use spaces in names.
'''''Note'':''' Remember as previously stated you can use spaces in names.


<li> Copy '''.htaccess''' from the root folder '''www''' to folder '''secure2''' once copied open the file and delete its contents, add the following:
&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:


<pre>
&lt;pre&gt;
AuthName "Private area Please Login"
AuthName &quot;Private area Please Login&quot;
AuthType Basic
AuthType Basic
AuthUserFile /htpasswd/www/.htpasswd
AuthUserFile /htpasswd/www/.htpasswd
Line 164: Line 165:
RewriteCond %{REMOTE_user} ^Ruth\ Smith$
RewriteCond %{REMOTE_user} ^Ruth\ Smith$
RewriteRule  ^(.*) secure2/mpg3/$1 [R,L]
RewriteRule  ^(.*) secure2/mpg3/$1 [R,L]
</pre>
&lt;/pre&gt;
</ol>
&lt;/ol&gt;
*Each page to be protected requires three lines:
*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.
:* 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