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

Asked

Viewed 845 times

1

Folks I’m trying to rewrite in . htaccess to force https on all pages and hide the . php extension. He’s staying at the kinghost and I already have the certificate. I have separate codes but I couldn’t do both together where every page contains https and no extension . php example : https://menudominio/contact us

htaccess code to remove the . 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]

1 answer

3


Just add in the desired order and always add the flag L for each RewriteRule that should not mix, it is only necessary a on

Should stay 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] which I have added to the specific case is unnecessary, but come 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.