Remove www and force https [duplicate]

Remove www and force https [duplicate] - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Remove www and force https [duplicate] error on your web browser. Problem :






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 www. 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 ^(.*)$ http://example.com/$1 [L,R=301]

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


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


Solution :

I´d suggest:



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

# Redirect from the `http://` to the `https://` version of the URL.
# https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %HTTPS !=on
RewriteRule ^(.*)$ https://%HTTP_HOST/$1 [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>

We hope that this article has helped you resolve the htaccess, redirects, https error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

Redirected urls show in serp, with the original permalink but with the title and meta of the target page

How can I redirect everything but the index as 410?

How do I redirect traffic only if being accessed from a specific port?