Apache2

Hints and Tricks related to Apache2 Web-Server

mod_rewrite

Place the lines into the VirtualHost config or the .htaccess file.

Redirect domain-name to one common one

(like hostname.com or experiment.hostname.com to www.hostname.com)

Useful if you have multiple domain names pointing to the same site, but only one SSL certificate configured. Note the redirect Url contains https. The rule e.g. reads: «everything that is not the configured hostname in the condition, rewrite it».

RewriteEngine OnRewriteCond %{HTTP_HOST} !^www.hostname.com$ [NC] RewriteRule ^(.*)$ https://www.hostname.com$1 [R=301,L,QSA]

Redirect requests HTTP to the HTTPS:

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