Reputation: 1350
I've begun the process of rebuilding a site within Laravel 4.
The URLs of this site are currently served with the .php extension. Customers have these pages bookmarked so it's important I redirect them to the same page minus the .php extension.
Example: I would like /contact.php
to redirect to /contact
.
Laravel ships with this in its htaccess file:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I'm not well versed in regular expressions or Apache's own syntax. I found this comprehensive answer to serving php files without the .php extension, but Laravel routes everything through index.php, so that solution doesn't seem to work.
How do I universally redirect URLs with .php to the same page without the extension?
Upvotes: 1
Views: 774
Reputation: 143906
Above the rules that you already have, add this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.php$ /$1 [L,R=301]
to redirect non-existent php pages.
Upvotes: 2