Question

Redirect http request -> https

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): <VirtualHost *:443> 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/
    <Location /cgi-bin>
            Options +ExecCGI
    </Location>
  SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

</VirtualHost>

and it works well, but I’ll have issue in redirecting http traffic. I tried with: <VirtualHost *:80> ServerName emmepiesse.no-ip.org Redirect / https://emmepiesse.no-ip.org:443 </VirtualHost> but no luck. Ideas? Thank you in advance


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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: <br> <br>Redirect permanent / https://emmepiesse.no-ip.org:443 <br> <br>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: <br> <br>RewriteEngine On <br>RewriteCond %{HTTPS} off <br>RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} <br> <br>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.