Hi, I have enabled Let’s Encrypt on Ubuntu 14.04 and used the auto option to re-direct all http requests to https. This is working fine.
However, I now want to use mod_rewrite to use cleanurls on my site - all I need to do is remove the .php extension from all filenames.
I have tried adding the following rewrite rule to my .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
This works fine on my (MAMP) localhost but does not work on the instance running Lets Encrypt.
I have tested that the .htaccess is working by adding this rule which works as expected (redirecting all www requests to the root domain)
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
I suspect that there may be some conflict between the Lets Encrypt auto setup option and my mod_rewrite rule but I am stuck as to how to make them both work together.
Any help much appreciated.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Generally I would first recommend making sure that you had done a a2enmod rewrite, restarted apache and made sure you had set AllowOverride All in your apache configuration but since you’ve confirmed that rewrite is working I would suggest trying this slightly different version of the rewrite rule.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
When using an .htaccess file it will take precedence over rewrites specified in your configuration when AllowOverride is set to All so it’s unlikely that the letsencrypt changes are directly responsible.
Thanks ryanpq. I tried using this alternative rule, but it had no effect. In the meantime however I have discovered that the cause of the problem was a conflict with MultiViews being enabled on the server (I was not previously aware of the existence of MultiViews).
In order to fix this particular issue I added the following line to the .htaccess file
Options -MultiViews
Posting the answer here in case it helps others.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.