Adding Self-Signed SSL For Local Web Development with https Auto-Redirect

1. Generated a server certificate and server private key

http://www.selfsignedcertificate.com/

2. Download the files, e.g.

9264078_local.dev.mydomain.com.cert
9264078_local.dev.mydomain.com.key

and put them in your Apache conf folder, e.g. C:Apache24conf

3. Edit conf/httpd.conf, uncomment the following lines

LoadModule log_config_module modules/mod_log_config.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
Include conf/extra/httpd-ssl.conf
Include conf/extra/httpd-vhosts.conf

4.  Edit conf/extra/httpd_ssl.conf

Uncomment

Listen 443
SSLEngine on

and edit

DocumentRoot “C:UsersayahyaDocumentsmydomainwww” (point to your webroot)
ServerAlias *.mydomain.com:443

SSLCertificateFile “c:/Apache24/conf/9264078_local.dev.mydomain.com.cert”
SSLCertificateKeyFile “c:/Apache24/conf/9264078_local.dev.mydomain.com.key”

5. Edit conf/extra/httpd_vhosts.conf

Add some virtual hosts, e.g.

<VirtualHost *:80>
ServerName local.dev.mydomain.com
ServerAlias local.dev.www.mydomain.com
DocumentRoot “C:UsersayahyaDocumentsmydomainwww”
ErrorLog “logs/corpsite-error.log”
CustomLog “logs/corpsite-access.log” common

RewriteEngine on

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://local.dev.mydomain.com$1
</VirtualHost>

6. Restart Apache and Test

If you restart Apache and get errors, restart Apache from the command line to see the errors.

If you can restart and you go to http://local.dev.mydomain.com, you’ll get redirected to https://local.dev.mydomain.com