1

I need an .htaccess file which will do something like this:

  1. When user input www.site.com/some_folder/test it will keep the address as it is and open the corresponding page (test.php)
  2. When user input www.site.com/some_folder/test.php it will remove .php extension to www.site.com/some_folder/test and it will open the corresponding page (test.php)

What I have right now is:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

and it can only fulfill first scenario but not the second. (when I input www.site.com/some_folder/test.php it will still show www.site.com/some_folder/test.php)

What should I change / add in the .htaccess file to fulfill 2nd scenario ?

Any help will be very much appreciated.

Thanks very much.

4

1 回答 1

0

add the following directives to your .htaccess:

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule (.*)\.php$ /$1 [R=301,L,QSA,NC]

Edit: if you're in Localhost :

RewriteBase /sitename/
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule (.*)\.php$ $1 [R=301,L,QSA,NC]
于 2013-07-03T12:02:56.583 回答