Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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
URL 404s正在子目录(.htaccess)中查找index.php_Php_Html_Apache_.htaccess - Fatal编程技术网

URL 404s正在子目录(.htaccess)中查找index.php

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,但它返回了404未找到错误。文件结构如下所示:

| 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进行测试