views:

48

answers:

1

Have the following mod_rewrite rule:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME}\.php -f
 RewriteRule ^(.*)$ $1.php
 RewriteRule ^index\.php$ / [R=301,L]
</IfModule>

Which strips .php from any of my urls.

However, if I try to specify a 301 redirect to a page that already exists as such:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME}\.php -f
 RewriteRule ^(.*)$ $1.php
 RewriteRule ^index\.php$ / [R=301,L]
 RewriteRule ^something-page\.php$ /something-page [R=301,L]
</IfModule>

The server can't resolve the domain.

I'm thinking I have seem to have put myself into a recursive loop.

Any help much appreciated!

A: 
RewriteRule ^(.*)$ $1.php

This will redirect "/something-page" to "/soemthing-page.php", which will then in turn hit this:

RewriteRule ^something-page\.php$ /something-page [R=301,L]

Place the something-page rule above the generic .php rewrite rule, and mark it [L].

Drew
Thanks Drew, tried that - but to no avail I'm afraid. It still chokes on the URI.
dikjones
So put the rewrite rule to the top - and marked it [L]. Still to no avail, seems to still process the generic ^(.*)$ $1.php.Essentially google has indexed some of my /foo.php pages, which I'd obviously like to redirect 301 to /foo - but I can't seem to get the rule to work as expected.Any help, would be much appreciated.
dikjones