Mobile app version of vmapp.org
Login or Join
Hamaas447

: Remove www and force https This has been asked multiple times, but none of the answers have worked for me. I have just installed an SSL certificate and need to force https connections for

@Hamaas447

Posted in: #Htaccess #Https #NoWww #Redirects

This has been asked multiple times, but none of the answers have worked for me.

I have just installed an SSL certificate and need to force https connections for all visitors.

This site has a lot of incoming links, so all existing http links should properly redirect to https.

There should be no There is also a rule that removes .html from files for "friendly" URLs, so that has to continue to work.

This is the old htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ example.com/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ .html [NC,L]


What is the new set of rules I need to use?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamaas447

1 Comments

Sorted by latest first Latest Oldest Best

 

@Rambettina238

I´d suggest:

# ----------------------------------------------------------------------
# | Forcing `https://` |
# ----------------------------------------------------------------------

# Redirect from the `http://` to the `https://` version of the URL.
# wiki.apache.org/httpd/RewriteHTTPToHTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ %{HTTP_HOST}/ [R=301,L]
</IfModule>

# ----------------------------------------------------------------------
# | Suppressing the `www.` at the beginning of URLs |
# ----------------------------------------------------------------------

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^ %{ENV:PROTO}://%1%{REQUEST_URI} [R=301,L]
</IfModule>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme