Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm attempting to redirect any requests for a PHP file to the site root, is there any way to do this? We performed a large site upgrade but we want to prevent errors caused by people being referred from old links from Google.

I had attempted to use the following, but it's causing a few issues with our system.

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php /

We've tried numerous similar ideas, has anyone got a better one (that works)? :D

Update: I forgot to mention that the system we use uses mod_rewrite to direct SEO-friendly URLs to pages. Theoretically there are no direct .php file references in a correct URL. The problem with the above solution is that it seems to bugger up a couple of our scripts, though I have no idea why.

share|improve this question

If these pages are going to return a 404 error page, you can simply override the 404 error page and make it a meta redirect to the home page. This would capture not only files ending in .php but any page which doesn't exist, I'm not sure if that's what you want.

share|improve this answer
Thanks for the suggestion - I did actually try doing it that way before I realised that wrong URLs didn't actually produce a 404, but an XSL compile error in the software (we use Symphony CMS). It might be a good plan to drop the redirect into compile error pages, as we don't want people to see those anyway. – robotmay Oct 16 '09 at 5:45

Much as I love mod_rewrite, in this case you might want to try mod_alias instead:

    <Location />
            DirectoryIndex index.html
    RedirectMatch permanent \.php$ /
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.