Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/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
Apache htaccess重写引擎导致子目录问题_Apache_.htaccess_Hosting - Fatal编程技术网

Apache htaccess重写引擎导致子目录问题

Apache htaccess重写引擎导致子目录问题,apache,.htaccess,hosting,Apache,.htaccess,Hosting,给你们提个问题。我的网站的基本文件结构如下: DirectoryIndex index.php www.example.com / index.php otherFiles.php /目录 index.php 当前,如果您要键入example.com/directory,它将重定向到我的404页面。您必须键入example.com/directory/index。我的假设是,对于每个目录,默认页面都是带有.php或.html扩展名的index。我猜我错了,所以我将该目录的.htacce

给你们提个问题。我的网站的基本文件结构如下:

DirectoryIndex index.php
www.example.com

/

index.php

otherFiles.php

/目录

   index.php
当前,如果您要键入example.com/directory,它将重定向到我的404页面。您必须键入example.com/directory/index。我的假设是,对于每个目录,默认页面都是带有
.php
.html
扩展名的
index
。我猜我错了,所以我将该目录的
.htaccess
配置如下:

DirectoryIndex index.php
但是,没有任何进展。我有什么遗漏吗?为了澄清,我想使用example.com/directory的url打开该目录中的索引文件。这是我的通用
.htaccess

ErrorDocument 404 http://www.example.com/404

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
编辑
因此,我注释掉了htaccess中的3个
Rewrite
命令,现在我的问题得到了解决。问题是现在显示的是php文件扩展名。有没有一种方法可以在不干扰默认索引页的情况下包含重写规则?还是问题出在别的地方

看起来404是由于目录
/directory.php
不存在。因为您的
重写规则执行的条件只是它不是一个真实的文件(
%{REQUEST\u FILENAME}!-f
),所以该规则被错误地应用于目录,试图附加
.php
。它很容易用
修复-d

ErrorDocument 404 http://www.example.com/404

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

现在,当请求像
/directory
这样的目录时,将使用默认的
DirectoryIndex
,并且不会进行重写。

由于某种原因,这只适用于目录和另一个根php文件,其他页面会导致404错误。出于某种原因,更新只需要很长时间。谢谢