2014-03-24 96 views
1

我目前有一些代碼添加到我的.htaccess文件,它的工作原理。.htaccess刪除.php,但添加/末尾

RewriteEngine On 

# hide .php extension snippet 
# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R,L] 

# To internally forward /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.*?)/?$ $1.php [L] 

,比如我有= http://www.hello.com/world.php

此代碼刪除PHP和看起來像這樣http://www.hello.com/world

我希望它看起來像這樣= http://www.hello.com/world/

如何添加/ 到最後?

謝謝先進。 -O

回答

1

您可以使用此:

RewriteEngine On 

# hide .php extension snippet 
# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1/ [R,L] 

# To internally forward /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 
+1

記住修復'.php'爲'\ .php'爲'filephp'否則會匹配。 – h2ooooooo