Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
add an example of using include
Source Link
spacepickle
  • 2.8k
  • 19
  • 21

The definition for HTTPS and HTTP version of your site must (?) appear under different virtualhost entries (unless you are using some proxy in front of httpd).

This makes it easy to end up with differences between the configs in the two virtualhosts. Make sure the config for the redirect is the same in both virtualhosts for port 80 and port 443

The easiest way to do this is to make use of an Include statement and reference a common file in the two virtualhost definitions

For instance put these rewrites in a file base-rewrite.inc in the root config dorectory (/etc/apache2/base-rewrite.inc in debian/ubuntu; /etc/httpd/base-rewrite.inc in Redhat):

RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE] 

Then in your virtual hosts definition, Include this file:

<VirtualHost *:80> # HTTP default virtualhost ServerName www.example.com DocumentRoot /var/www/html/ Include base-rewrite.inc </VirtualHost> <VirtualHost *:443> # HTTPS default virtualhost ServerName www.example.com DocumentRoot /var/www/html/ # An example SSL config, but use your certificate files SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key Include base-rewrite.inc </VirtualHost> 

This will keep the rewrites consistent and make it easy to maintain and change them all at once

The definition for HTTPS and HTTP version of your site must (?) appear under different virtualhost entries (unless you are using some proxy in front of httpd).

This makes it easy to end up with differences between the configs in the two virtualhosts. Make sure the config for the redirect is the same in both virtualhosts for port 80 and port 443

The easiest way to do this is to make use of an Include statement and reference a common file in the two virtualhost definitions

The definition for HTTPS and HTTP version of your site must (?) appear under different virtualhost entries (unless you are using some proxy in front of httpd).

This makes it easy to end up with differences between the configs in the two virtualhosts. Make sure the config for the redirect is the same in both virtualhosts for port 80 and port 443

The easiest way to do this is to make use of an Include statement and reference a common file in the two virtualhost definitions

For instance put these rewrites in a file base-rewrite.inc in the root config dorectory (/etc/apache2/base-rewrite.inc in debian/ubuntu; /etc/httpd/base-rewrite.inc in Redhat):

RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE] 

Then in your virtual hosts definition, Include this file:

<VirtualHost *:80> # HTTP default virtualhost ServerName www.example.com DocumentRoot /var/www/html/ Include base-rewrite.inc </VirtualHost> <VirtualHost *:443> # HTTPS default virtualhost ServerName www.example.com DocumentRoot /var/www/html/ # An example SSL config, but use your certificate files SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key Include base-rewrite.inc </VirtualHost> 

This will keep the rewrites consistent and make it easy to maintain and change them all at once

Bounty Awarded with 50 reputation awarded by webtweakers
Source Link
spacepickle
  • 2.8k
  • 19
  • 21

The definition for HTTPS and HTTP version of your site must (?) appear under different virtualhost entries (unless you are using some proxy in front of httpd).

This makes it easy to end up with differences between the configs in the two virtualhosts. Make sure the config for the redirect is the same in both virtualhosts for port 80 and port 443

The easiest way to do this is to make use of an Include statement and reference a common file in the two virtualhost definitions