如何隐藏.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]
你能在我的系统中添加屏幕截图吗?也许你可以接受我的答案?谢谢