How to perform a 301 redirect of all .php URLs to clean URLs?

Posted by spacedatdusk on Stack Overflow See other posts from Stack Overflow or by spacedatdusk
Published on 2010-04-02T00:20:41Z Indexed on 2010/04/02 0:23 UTC
Read the original article Hit count: 616

Filed under:
|
|
|
|

My htaccess isn't quite working the way I want it to. I've seen some similar threads on here but they aren't quite what I need and I don't know enough yet about htaccess to modify the code to suit my needs.

This is what I have working so far: I've got all non-www URLs redirecting to www URLs and I'm doing an internal rewrite of all URLs to the corresponding PHP file on the server. In the files I have relative links that are clean without any file extension on them.

This is what I need to do yet: All the pages on my site are still accessible through URLs with .php on the end. For SEO reasons I want the URL's with .php to all do an external 301 redirect to the clean URL without the extension.

Here's what I have in my htaccess file that's in the root folder on my server.

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

I'd appreciate any help. Thanks in advance!

© Stack Overflow or respective owner

Related posts about php

Related posts about htaccess