Difference between revisions of "Htaccess"

From KOP KB
Jump to: navigation, search
(Auth for Single Page)
(Auth for Single Page)
Line 31: Line 31:
 
== Auth for Single Page ==
 
== Auth for Single Page ==
 
Protect pages via htaccess or even whole directories.
 
Protect pages via htaccess or even whole directories.
 +
 +
This will help with creating the htpasswd file
 +
http://www.htaccesstools.com/htpasswd-generator/
 
<syntaxhighlight lang="apache">
 
<syntaxhighlight lang="apache">
 
AuthType Basic
 
AuthType Basic

Revision as of 22:30, 25 September 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/

Auth for Single Page

Protect pages via htaccess or even whole directories.

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

AuthType Basic
AuthName "Protected Page"
AuthUserFile /Full/Path/To/.htpasswd

<Files "mypage.html">
  #if you want the whole directory you don't require the Files clause here
  Require valid-user
</Files>