Apply two functions to .htaccess

1

I do not quite understand .htacces, but I use it to force my site navigation to the link , now I'm trying to implement a code to remove .html > of the URL, I already did that, but when I put the two together it does not work.

Force https:

RewriteEngine on
RewriteCond     %{SERVER_PORT} ^80$
RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] 

Remove .html from URL:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301] 

How do I make the two work together?

    
asked by anonymous 22.11.2017 / 13:31

1 answer

1

When RewriteRule matches, the flag [L] ( LAST ) stops processing other rules. You have to remove it from the first rule.

RewriteEngine On

#Forçar https
RewriteCond     %{SERVER_PORT}      ^80$
RewriteRule     ^                   https://%{SERVER_NAME}%{REQUEST_URI} [R]

#Retirar .html da URL
RewriteCond     %{REQUEST_FILENAME} !-d
RewriteRule     ^(.*)\.html$        $1        [NC,R=301]

And after the redirect, if you want to rewrite all requests without .html to the page with .html , you can add:

#Reescrever o .html (adicionado internamente, o usuário não o vê)    
RewriteCond     %{REQUEST_FILENAME} !-f
RewriteCond     %{REQUEST_FILENAME} !-d
RewriteRule     ^((?:[^.]*|.*[^.]{5})[./])$   $1.html
    
23.11.2017 / 07:54