Question

Redirect http request -> https

Posted April 25, 2013 5.7k views
Hi!! I activated 5$ plan vps yesterday, I'm quite impressed. I'm developing a management application, that have to run throught ssl. I created this virtualhost (following the guide on digital ocean): ServerAdmin maltesepiero@gmail.com ServerName emmepiesse.no-ip.org:443 ServerAlias www.emmepiesse.no-ip.org:443 DirectoryIndex index.html DocumentRoot /var/www/mps # CGI Directory ScriptAlias /cgi-bin/ /var/www/mps/cgi-bin/ Options +ExecCGI SSLEngine on SSLCertificateFile /etc/apache2/ssl/apache.crt SSLCertificateKeyFile /etc/apache2/ssl/apache.key and it works well, but I'll have issue in redirecting http traffic. I tried with: ServerName emmepiesse.no-ip.org Redirect / https://emmepiesse.no-ip.org:443 but no luck. Ideas? Thank you in advance

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

1 answer
The issue with the redirect is that you won't be able to preserve for the REQUEST_URI so if a user goes to http://emmepiesse.no-ip.org/blog they will end up on https://emmepiesse.no-ip.org - as for why the redirect isn't working you may want to update it to:

Redirect permanent / https://emmepiesse.no-ip.org:443

Alternatively you can use .htaccess + mod_rewrite to setup a rewrite rule as follows which would redirect requests and also preserve the requested path/document:

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

You can also replace HTTP_HOST with SERVER_HOST, HTTP_HOST refers to what the user provided in his URL when using his browser, while the SERVER_HOST refers to the Server Name that was defined in the config file for which the domain/IP matched in your configuration.
Submit an Answer