-4

How can I force https:// and www. but also remove .html from my url, I have searched around for this but all of the results wont load my website and they say my website redirected too many times

  • Learn more about ``pretty URLs`` and ``rewrite rules`` https://stackoverflow.com/questions/25080835/pretty-urls-with-htaccess – OMi Shah Mar 07 '21 at 05:52

1 Answers1

0

Try adding this to your .htaccess file. When you were previously making changes and causing redirect loops, were you doing something similar to your .htaccess file?

If so, I'm going to guess you're behind Cloudflare or a similar proxy :-)

<IfModule mod_rewrite.c>
    # If behind a proxy (e.g. Cloudflare)
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    # If not HTTPS
    RewriteCond %{HTTPS} off
    # Rewrite to HTTPS
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # If missing www.
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    # Rewrite to include www.
    RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # If a filename
    RewriteCond %{REQUEST_FILENAME} !-f
    # Rewrite removing .html (e.g. www.test.com/index.html --> www.test.com/index)
    RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
Sammy
  • 185
  • 1
  • 11