Htaccess multiple 301 redirects

.htaccessredirect

I am looking for some help with setting up some redirect rules in my htaccess file. I have switched the site to run on Codeigniter, and basically all pages ending in .php, now just have that ending removed, ie www.mysite.com/foo/bar.php is now www.mysite.com/foo/bar

I have tried just listing the redirects like so:

Redirect 301 http://mysite.com/foo/bar.php http://mysite.com/foo/bar
Redirect 301 http://mysite.com/foo/bar/bar.php http://mysite.com/foo/bar/bar
Redirect 301 http://mysite.com/foo/bar/foo.php http://mysite.com/foo/bar/foo

etc (About 12 rules needed). Bizarrely, it works for the first rule but not the others? Am I not listing them correctly? Everything I've read tells me this is how it is to be written. So what am I doing wrong?

Additional Information that may be relevant:

My htaccess file already contains the following code (for removing 'index.php' from urls):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Not sure if it matters if this is placed before or after the rewrites? Also, the site in question is an addon domain. I am not entirely sure whether these rewrites should be placed in the .htaccess file in the public folder of the master site, or in the addon domain's subdirectory? (I've tried both, with the same result).

Help please! Thanks in advance.

Best Solution

Sorry, I've just solved this. I removed the base URL from each rule and now it works. ie:

Redirect 301 /foo/bar.php /foo/bar

Instead of:

Redirect 301 http://mysite.com/foo/bar.php http://mysite.com/foo/bar

Not entrirely sure why... need to read up.

Related Question