.htaccess: redirect www, force https and remove .php | Double Marvellous
Back to Blog
Development Jul 17, 2024 4 min read

.htaccess: redirect www, force https and remove .php

.htaccess: redirect www, force https and remove .php

Force http to https, force www to non-www and remove the file extension for .php on urls
If you are using WordPress then you’ll know that it already removes the .php file extension to give you nice clean urls. And if you’ve used Codeigniter you’ll know you have to stroll into the htaccess to make the urls look normal during setup. Well here I just have a normal website – gasp! – built in php and I needed to do these three things together from the .htaccess file.

Remember, this forces www to non-www! Enjoy

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Double Marvellous

AI Chatbot

Double Marvellous.