使用mod_rewrite和SEO问题删除.php扩展名

I'm trying to use modrewrite to change my urls from /foo.php to /foo and from /foo.php?lang=en to /en/foo. The problem I have is that I think I need to use 301 redirect to move the .php-less address to the .php address, or else my ranking will be splitted among these 2. But if I use [R=301] the address in the bar changes to the .php one making my pretty url efforts quite useless. What should I do?

I've looked around for any question\tutorial i could find but I can't fully understand modrewrite. The main issue I have is that if I change my .htaccess file then revisit an already visited page the new .htaccess is not working but is somehow caching the old result making correction a real pain. Do you know a workaround?

Thank you,

Mokuchan

You definitely must look at Apache modul mod_rewrite and general idea of rewriting urls.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Sounds like MultiViews would be a better solution than rewriting the URL. Just put this in your .htaccess. What that will do is essentially, if i type in stackoverflow.com/pages it will first look for a directory named pages, if it can't find it, a file. You can then have stackoverflow.com/pages/view/some/page where /view/some/page is the query.

Options Indexes FollowSymLinks Includes MultiViews

Edit To get the /view/some/page/ use $_SERVER['PATH_INFO'];