I am trying to archieve the following with least amount of redirects;
- Remove WWW
- Force HTTPS
- Remove php extension
- Remove end trailing slash
What i have so far and is working:
RewriteEngine On
# REMOVE WWW
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# FORCE HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# REMOVE TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# REMOVE PHP EXTENSION
RewriteRule ^(.+)\.php$ /$1 [NC,L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ /$1.php [END]
Current behaviour:
http://www.example.com/functions.php -> https://example.com/functions
(works with 4 redirects)
OR
http://www.example.com/functions/ -> https://example.com/functions
(works with 4 redirects)
Does anyone have any suggestions how to make this work with fewest possible redirects?