我使用此代码删除了我网站上的.php文件扩展名
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
这可以将我的网址从example.com/contact/contact.php更改为example.com/contact/contact,但我希望网址在文件夹之后没有文件名。我希望它看起来像example.com/contact/任何想法?
答案 0 :(得分:1)
一种简单的方法是在导航到文件夹时命名文件index.php,将提供index.php文件。 因此,当导航到/ contact /contact/index.php时将会显示。