Difference between revisions of "Htaccess"

From KOP KB
Jump to: navigation, search
(301 Redirect)
(Auth for Single Page or Multiple)
Line 44: Line 44:
  
 
<Files "mypage.html">
 
<Files "mypage.html">
  #if you want the whole directory you don't require the Files clause here
+
#if you want the whole directory you don't require the Files clause here
  # also if you have the entirety of the auth info in the files clause you can do separate files with separate login information
+
# also if you have the entirety of the auth info in the files clause you can do separate files with separate login information
  AuthType Basic
+
AuthType Basic
  AuthName "Protected Page"
+
AuthName "Protected Page"
  AuthUserFile /Full/Path/To/.htpasswd
+
AuthUserFile /Full/Path/To/.htpasswd
  Require valid-user
+
Require valid-user
 
</Files>
 
</Files>
  
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 17:31, 8 October 2014

Redirect for SSL

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [NC,R,L]

Another SSL redirect option

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Two domains pointing at a website one has a different starting point.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^$ http://domain.com/filename.html [L,R=301]

301 Redirect

Redirect 301 /oldfile.htm http://example.net/

Note that while the old file is a necessary parameter, it can be set to '/' (without the single quotes) to define all requests to that folder. Such as:

Redirect 301 / http://example.net/

Auth for Single Page or Multiple

Protect pages via htaccess or even whole directories.

This will help with creating the htpasswd file http://www.htaccesstools.com/htpasswd-generator/

<Files "mypage.html">
#if you want the whole directory you don't require the Files clause here
# also if you have the entirety of the auth info in the files clause you can do separate files with separate login information
AuthType Basic
AuthName "Protected Page"
AuthUserFile /Full/Path/To/.htpasswd
Require valid-user
</Files>