Difference between revisions of ".htaccess"

From Hostek.com Wiki
Jump to: navigation, search
(Can I use a .htaccess file to password protect a directory?)
Line 17: Line 17:
 
Add the following to your .htaccess file:
 
Add the following to your .htaccess file:
 
<pre>CheckSpelling on</pre>
 
<pre>CheckSpelling on</pre>
 +
 +
==Rewriting all URL requests to WWW.==
 +
Add the following to your .htaccess code:
 +
<pre>
 +
RewriteEngine On
 +
RewriteCond %{HTTP_HOST} !^www\.
 +
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
 +
</pre>
 +
 +
==Rewriting HTTP requests to HTTPS==
 +
Add the following to your .htaccess code:
 +
<pre>
 +
RewriteEngine On
 +
RewriteCond %{HTTPS} !^on$
 +
RewriteRule (.*) https://yourdomain/$1 [R,L]
 +
</pre>
  
 
[[Category:Linux]]
 
[[Category:Linux]]

Revision as of 22:38, 4 July 2014

Can I use a .htaccess file to password protect a directory?

Yes, on our LINUX servers you can use a .htaccess file to password protect a directory.

The code to perform this is:

AuthUserFile /usr/local/you/safedir/.htpasswd
AuthGroupFile /dev/null
AuthName EnterPassword
AuthType Basic

require user wsabstract

Change the File directory to the directory listed in your File Manager.

Enabling Case Insensitive URLs for my Linux site

Add the following to your .htaccess file:

CheckSpelling on

Rewriting all URL requests to WWW.

Add the following to your .htaccess code:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Rewriting HTTP requests to HTTPS

Add the following to your .htaccess code:

RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://yourdomain/$1 [R,L]