remove the php extension and force any page as https via htaccess

0

Personal I'm trying to make a rule in .htaccess to force https on all pages and hide the .php extension. It is hosted on kinghost and I already have the certificate. I have the separate codes but I could not do the two things together where every page contains https and no extension .php example: link

htaccess code to remove .php extension

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

htaccess code to force https

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://seusitecomhttps.com.br/$1 [R,L]
    
asked by anonymous 22.08.2017 / 02:27

1 answer

1

Just add in the desired order and always add the L flag to every RewriteRule that should not mix, only a on is required

It should look like this:

RewriteEngine on

# Redireciona para HTTPS se estiver na porta 80
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://seusitecomhttps.com.br/$1 [R,L]

# Reescreve as URLs
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php [L]

The last [L] that I added to the specific case is unnecessary, but perhaps add new rules that have no relation to RewriteRule ^(.*)$ $1.php will be good to "avoid" conflicts, of course it depends a lot on the new rules. >     

22.08.2017 / 03:04