2014-01-16 50 views
0

從文件中刪除.PHP我想從每個URL tream .PHP像localhost/index.php --->localhost/index 但我也想localhost/index/工作過....使用htacess

下面是當前代碼我正在使用

#for hiding.php extension 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteCond %{REQUEST_URI} !/$ 
RewriteRule ^(.*)/?$ $1\.php [NC] 
############################-------- END ---------######################## 

有人可以提出更改嗎?

+0

看看這個Q&A:http://stackoverflow.com/questions/1068595/htaccess-code-to-remove-extension-and-addforce-trailing-slash – vbo

回答

1

嘗試:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.*?)/?$ /$1.php [L] 
+0

感謝的人。 .. 有效.. –