.htaccess没有按预期工作

时间:2012-01-22 15:00:37

标签: .htaccess

我的.htaccess文件无效。我已检查它是否在根目录中。我还验证了它的代码是正确的。当我在.htaccess中输入随机字母/数字时,我没有得到500错误。当我打开我的apache错误日志时,它给了我这个错误:

[Mon Jan 16 20:28:37 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Mon Jan 16 20:28:41 2012] [notice] Digest: generating secret for digest authentication ...
[Mon Jan 16 20:28:41 2012] [notice] Digest: done
[Mon Jan 16 20:28:44 2012] [notice] Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations

我不知道该怎么做。

http.conf:

<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>

1 个答案:

答案 0 :(得分:3)

有一些可能的原因导致您的随机,无效.htaccess文件不会导致http错误500(内部服务器错误):

  • 文件名不正确。它必须是.htaccess。第一个字符是一个点。最后一个字符是小写的''。隐藏的扩展名可能会导致问题,因为错误的文件名可能看起来是正确的。
  • 文件位置不正确。尝试将文件放在html文件旁边的同一文件夹中。如果可行,您可以将文件移到一个文件夹中再试一次。
  • Apache配置不允许.htaccess个文件。如果配置选项AllowOverride在apache配置文件中设置为None(对于指定的域),那么Apache将不会查找任何.htaccess文件。

另请注意,使用.htaccess协议访问文件时会忽略file://个文件。

<强>更新

.htaccess中使用的路径是指文件系统路径,而不是url路径。根据您发布的.htaccess内容,没有人可以访问您网络服务器上的任何文件。我会建议像:

<Directory />
    # Security first, deny everything that's not explicitly allowed.
    AllowOverride None
    Order deny, allow
    Deny from all
</Directory>

<Directory /path/to/webroot>
    # This is the part that should be accessible
    Options FollowSymLinks
    AllowOverride All
    Order allow, deny
    Allow from all
</Directory>

您的.htaccess文件应位于/path/to/webroot 请注意,您应该将/path/to/webroot更改为与文件系统匹配的合理内容。

相关问题