how do i redirect http to https and remove html from the same rewrite rule?

You can use a single redirect rule like this:

ErrorDocument 404 /404.html
RewriteEngine on

#force https+www and remove .html
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
RewriteCond %{THE_REQUEST} /[^.\s]+\.html [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*?)(?:\.html)?$ https://www.%1/$1 [L,R=301,NC]

RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top