Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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_Mod Rewrite_Clean Urls - Fatal编程技术网

Apache 如何解决此.htaccess冲突?

Apache 如何解决此.htaccess冲突?,apache,.htaccess,mod-rewrite,clean-urls,Apache,.htaccess,Mod Rewrite,Clean Urls,我使用以下.htaccess规则来启用“干净”URL,即从文件名中删除.html扩展名: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.html [NC,L] 除了包含index.html的目录外,它在站点上90%的目录中都能正常工作。将这些目录链接为/directory会导致以下错误: 禁止的 您没有访问此服务器上的/directory/.html的权限 此外,在尝试查找时遇到404 Not Found错误 使用E

我使用以下.htaccess规则来启用“干净”URL,即从文件名中删除.html扩展名:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
除了包含index.html的目录外,它在站点上90%的目录中都能正常工作。将这些目录链接为/directory会导致以下错误:

禁止的

您没有访问此服务器上的/directory/.html的权限

此外,在尝试查找时遇到404 Not Found错误 使用ErrorDocument来处理请求

将这些目录链接为/directory/index是不可取的,因为其中包含“index”的URL是不可呈现的

为了解决这个问题,我尝试将这几个index.html文件重命名为index.htm,但在访问/directory时会出现相同的错误消息

我对这一部分尤其感到困惑:

您没有访问此服务器上的/directory/.html的权限

为什么Apache认为我正在尝试访问/directory/.html,而实际上我正在尝试访问index.htm

编辑: 根据Panama Jack的要求,我将在下面发布整个.htaccess文件

原件:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
编辑#1:

下面是apache错误日志中的一些条目 这些错误发生在我的原始.htaccess中

client denied by server configuration: /home/user/public_html/ar/.html
File does not exist: /home/user/public_html/403.shtml
client denied by server configuration: /home/user/public_html/zh_TW/.html
File does not exist: /home/user/public_html/403.shtml
这些错误发生在htaccess的Edit#1版本中:

File does not exist: /home/user/public_html/en/directory1, referer: http://example.com/en/directory1
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://example.com/en/directory1
File does not exist: /home/user/public_html/en/directory2, referer: http://example.com/
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://example.com/

这样试试你的规则

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)/?$ $1.html [NC,L]
编辑:


这有助于解决index.html错误,但现在还有另一个错误。没有找到。在此服务器上找不到请求的URL/目录。此外,尝试使用ErrorDocument处理请求时遇到500内部服务器错误。能否将其余的.htaccess规则添加到问题中。我已将这两个版本添加到问题中,谢谢。当您收到上面关于/目录的错误消息时,您的URL是什么样子的?当尝试访问example.com/file1时,URL栏显示,浏览器显示404和500个错误。尝试访问example.com/file1.html时,URL栏会显示,浏览器会正确显示页面。
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)/?$ $1.html [NC,L]
Options -Indexes -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.*)$ $1.html [L,NC]