Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何隐藏.php或.html扩展名_Php_.htaccess - Fatal编程技术网

如何隐藏.php或.html扩展名

如何隐藏.php或.html扩展名,php,.htaccess,Php,.htaccess,我在.htaccess文件中有这段代码,它隐藏了所有.php或.html扩展名,但默认情况下它不接受index.php或index.html #Alternate default index pagesDirectoryIndex first.html index.htm index.html index.php RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L

我在
.htaccess
文件中有这段代码,它隐藏了所有
.php
.html
扩展名,但默认情况下它不接受
index.php
index.html

 #Alternate default index pagesDirectoryIndex first.html index.htm index.html index.php
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^([^\.]+)$ $1.php [NC,L]
 RewriteRule ^([^\.]+)$ $1.html [NC,L]
它给出了这样的错误

The requested URL /example.com/aman/.php was not found on this server.
aman
文件夹中,我有一个
index.php
文件,默认情况下它不会使用该文件

 #Alternate default index pagesDirectoryIndex first.html index.htm index.html index.php
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^([^\.]+)$ $1.php [NC,L]
 RewriteRule ^([^\.]+)$ $1.html [NC,L]

有人能帮我修复这个错误吗?

这样不行。它在内部添加
.php
,但不删除它。你为什么只想让
.php
工作呢?你是说
example.com/aman/index
?这应该行得通

但只要使用:

example.com/aman/
如果你没有得到index.php服务,那么在你的.htaccess中添加如下内容:

DirectoryIndex index.php index.html index.htm
看。实际上,你已经把它注释掉了,就在你的规则之上,这似乎是你的问题。看起来您只需要将第一行更改为两行:

#Alternate default index pages
DirectoryIndex first.html index.htm index.html index.php
此外,字符类中不需要转义点/句点,因此将规则更改为:

RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteRule ^([^.]+)$ $1.html [NC,L]

你能在我的系统中添加屏幕截图吗?也许你可以接受我的答案?谢谢