vitaly78
By:
vitaly78

Rewrite Rule with SSL not working.

November 30, 2016 44 views
Apache Ubuntu 16.04

Hi
I have installed new server with Ubuntu 16.04
Installed SSL
Enabled rewrite mode

If I enter link as http://exemple.com/contact the page will work fine
If I enter same link or redirect to https:// the page gives me 404 error

How to fix this error, looks like redirection only works on http links because if I disable SSL my site works great.

This is the way my sites available conf file looks like:

<VirtualHost *:80>
<Directory /var/www/exemple.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
DocumentRoot /var/www/exemple.com
ServerName www.exemple.com
ServerAlias exemple.com
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>

    ServerAdmin webmaster@localhost
    ServerName exemple.com
    DocumentRoot /var/www/exemple.com

    #   SSL Engine Switch:
    #   Enable/Disable SSL for this virtual host.
    SSLEngine on

    #   A self-signed (snakeoil) certificate can be created by installing
    #   the ssl-cert package. See
    #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
    #   If both key and certificate are stored in the same file, only the
    #   SSLCertificateFile directive is needed.
    SSLCertificateFile /etc/apache2/ssl/ftaelectronics.com/XXXXXXXXXXXcrt
    SSLCertificateKeyFile /etc/apache2/ssl/ftaelectronics.com/XXXXXXX.key
    SSLCertificateChainFile /etc/apache2/ssl/ftaelectronics.com/XXXXXX.crt

</VirtualHost>

</IfModule>

1 Answer
xMudrii November 30, 2016
Accepted Answer

Try adding <Directory> directive to your SSL virtual host.

The same one you used for HTTP will do the job:

<Directory /var/www/exemple.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

So your config will look like:

<VirtualHost *:80>
<Directory /var/www/exemple.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
DocumentRoot /var/www/exemple.com
ServerName www.exemple.com
ServerAlias exemple.com
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>

    ServerAdmin webmaster@localhost
    ServerName exemple.com
    DocumentRoot /var/www/exemple.com

   <Directory /var/www/exemple.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

    #   SSL Engine Switch:
    #   Enable/Disable SSL for this virtual host.
    SSLEngine on

    #   A self-signed (snakeoil) certificate can be created by installing
    #   the ssl-cert package. See
    #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
    #   If both key and certificate are stored in the same file, only the
    #   SSLCertificateFile directive is needed.
    SSLCertificateFile /etc/apache2/ssl/ftaelectronics.com/XXXXXXXXXXXcrt
    SSLCertificateKeyFile /etc/apache2/ssl/ftaelectronics.com/XXXXXXX.key
    SSLCertificateChainFile /etc/apache2/ssl/ftaelectronics.com/XXXXXX.crt
</VirtualHost>

</IfModule>

Save file, exit editor and make sure you restart Apache:

  • sudo systemctl restart apache2

Try again and hope for best. :)

Have another answer? Share your knowledge.