1

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.