Rewrite

Redirect bla.com to www.bla.com

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

Redirect everything that is not bla.com to bla.com

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

Note, %{HTTP_HOST} contient aussi la partie avec le port, ie: bla.com:82 si on tape: http://bla.com:82/test

Redirect /everything.html but not /existingfile.html or /existingdir.html

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ /index.php?metaname=$1 [L,QSA]

HTTPS

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

Source: apache.org Rewrite HTTP to HTTPS

CVE-2011-3192 (2011-08-24)

Créer le fichier /etc/apache2/conf.d/CVE-2011-3192

# Drop the Range header when more than 5 ranges.
# CVE-2011-3192
SetEnvIf Range (,.*?){5,} bad-range=1
RequestHeader unset Range env=bad-range
# optional logging.
CustomLog /var/log/apache2/range-CVE-2011-3192.log common env=bad-range

On a aussi besoin du module headers.

a2enmod headers

On peut valider le tout avec

apache2ctl -t

Redémarrage

/etc/init.d/apache2 reload

Advisory: Range header DoS vulnerability Apache HTTPD 1.3/2.x \(CVE-2011-3192\)

Log

Il peut être utile d'ajouter dans les journaux d'erreur la requête, il faut utiliser la commande ErrorLogFormat

Dans le fichier /etc/apache2/apache2.conf

# apache2 version 2.4 : affiche le temps en microseconde GET /path/file?foo=bar
ErrorLogFormat request "[%{u}t] %{REQUEST_METHOD}e %{REQUEST_URI}e

# apache2 version 2.2 : pas moyen d'ajouter la requête

service apache2 reload

Fichiers journaux

Compression

À tester
<IfModule mod_deflate.c>
# Pour le texte (mod_deflate)  
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
AddOutputFilterByType DEFLATE application/json application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
<filesMatch "\.php$">
 SetOutputFilter DEFLATE
</filesMatch>
</IfModule>

PHP ? 
// on voit souvent:
	if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')){
		ob_start("ob_gzhandler");
	}else{
		else ob_start();
	}

// la documentation précise que ob_gzhandler est déjà conditionnelle au navigateur
ob_start("ob_gzhandler");

mod_deflate, filesMatch, conditional ob_start, Autre extension, autre extensions, ob_gzhandler, Output Compression on Wordpress Codex

Sécurité

XSS, Iframe, ...

Header always set X-FRAME-OPTIONS "DENY"
Header always set X-XSS-Protection "1; mode=block"
Header always set X-Content-Type-Options "nosniff"
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"