1

I currently use the following code in my .htacess to redirect non www to www and to redirect /pages (internally) to /pages.php etc.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^absoluteglazing.co.uk [NC]
RewriteRule ^(.*)$ http://www.absoluteglazing.co.uk/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]'

Now I have switched to https, this no longer works.

Can someone please let me know how to achieve the following using htaccess so it still works over https...

  • Redirect non www to www so everyone sees website with www
  • Redirect non https to https so everyone gets a secure connection
  • Redirect /pages to /pages.php internally to remove extension

Many thanks

TerryH
  • 33
  • 2
  • [Check this](http://stackoverflow.com/questions/17638611/redirect-all-http-and-https-non-www-urls-to-https-www-xyz-com-via-htaccess) – Condorcho Feb 24 '17 at 16:03

1 Answers1

0

To redirect http to https://www and to remove .php extension, you can use the following rules.

RewriteEngine on
#http to https +non-www to www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://www.%1%{REQUEST_URI} [NE,L,R]
#rewrite /page to /page.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*?)/?$ /$1.php [L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115