URL 404s正在子目录(.htaccess)中查找index.php
嘿,我试图链接到一个子目录,并在该目录中加载index.php,但它返回了404未找到错误。文件结构如下所示:URL 404s正在子目录(.htaccess)中查找index.php,php,html,apache,.htaccess,Php,Html,Apache,.htaccess,嘿,我试图链接到一个子目录,并在该目录中加载index.php,但它返回了404未找到错误。文件结构如下所示: | index.php | .htaccess | subfolder | index.php | about.php 当我转到mysite.com/subfolder时,我希望加载那里的index.php。我知道问题出在我的.htaccess文件上,因为当我删除它时,URL会起作用。以下是.htaccess中的代码: Options +MultiViews #
| index.php
| .htaccess
| subfolder
| index.php
| about.php
当我转到mysite.com/subfolder时,我希望加载那里的index.php。我知道问题出在我的.htaccess文件上,因为当我删除它时,URL会起作用。以下是.htaccess中的代码:
Options +MultiViews
# Remove file extensions from page names
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Disable Index Listing
Options -Indexes
Options +MultiViews
DirectorySlash On
DirectoryIndex index.php
我的猜测是,因为我正在删除文件扩展名,服务器正在查找
mysite/subfolder.php
,但找不到它,所以它将404。然而,我不熟悉.htaccess文件,它们对我来说仍然很神秘。在线搜索有很多代码,但没有解释任何东西是如何工作的。任何关于如何解决这个问题以及为什么解决方法有效的想法都会很有帮助 如果启用了多视图
选项,则不需要重写规则来处理扩展
只需在.htaccess中保留以下行:
Options +MultiViews
# Remove file extensions from page names
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Disable Index Listing
Options -Indexes
Options +MultiViews
DirectorySlash On
DirectoryIndex index.php
把其他东西都拿走。然后使用mysite.com/subfolder/
URL进行测试