使用.htaccess删除文件扩展名

时间:2018-08-26 20:11:11

标签: php .htaccess

我正在尝试在自己的网站上创建一个页面,其网址为http://localhost/logout/

我已经在该文件夹中创建了/logout/目录和index.php文件,但是由于我在转到http://localhost/logout/时删除了文件扩展名,因此出现404错误。

要真正进入该页面,我必须去http://localhost/logout/index,这不是我想要的。

我该如何解决?

.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Options -Indexes

1 个答案:

答案 0 :(得分:1)

不要删除.php扩展名,请将其添加到htaccess中:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
相关问题