User Tools

Site Tools


apache2

Table of Contents

Apache2

.htaccess

Enable PHP shorttags

php_value short_open_tag 1

Password-protected directory

AuthType Digest
AuthName "Restricted Files"
AuthUserFile /some/where/restricted.passwd
Require valid-user
$ htdigest [-c] /some/where/restricted.passwd 'Restricted Files' your_name

Overrule password-protection for a subdirectory

mod_rewrite

Deny access to subversion (.svn) directories

RewriteEngine on
RewriteRule ^(.*/)?\.svn/ - [F,L]

Alternative without mod-rewrite:

<DirectoryMatch \.svn>
	Order allow,deny
	Deny from all
</DirectoryMatch>

Redirect example.com to www.example.com

Redirect browser using HTTP-Status 301 Moved Permanently

ServerName www.example.com
ServerAlias example.com
 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=permanent,L]

An other example: Redirect everything which is NOT www., www2. or www3. to www.

ServerName www.example.com
ServerAlias example.com *.example.com
 
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www|www2|www3)\.example\.com [NC]
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=permanent,L]
apache2.txt · Last modified: 2011-09-23 17:36 CEST by dominik