Report this

What is the reason for this report?

Redirect to https not working if used with out www

Posted on January 30, 2015

I’m using Apache 2.4.7. on Ubuntu 14.04 LTS. Redirects to https work for all cases (eg. http://www.tripleaf.com goes to https)

However for one case it does not work: http://tripleaf.com or http://tripleaf.com/ does not redirect to https site but shows the directory listing. Please advice.

I also tried the answer at https://www.digitalocean.com/community/questions/change-default-http-to-https but same result.

My .htaccess is:

<IfModule mod_rewrite.c>
RewriteEngine on

# This checks to make sure the connection is not already HTTPS
RewriteCond %{HTTPS} !=on

# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

#RewriteCond %{HTTPS} off
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule> 


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!

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.

I have had success just using:

#redirect www to website root
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#force https 
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Probably if Serverpilot comes with its own set of redirects

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.