English 中文(简体)
为什么 Apache2.ht access 文件没有被读取? (.ht access 文件中的“options - Indexes”没有工作)
原标题:Why is the Apache2 .htaccess file not being read? ("Options -Indexes" in .htaccess file is not working)

我创建了一个只有以下线条的.httaccess文件:

选项 - Indexs

然而,仍然为目录显示索引。

我刚刚安装了Apache2, 并且正在使用所有的默认值( 我没有修改 apache2. conf 或 httpd. conf ) 。

OS: Ubuntu 12.04 (Precise Pangolin)
Apache2 version: Server version: Apache/2.2.22 (Ubuntu) Server built: Feb 13 2012 01:51:56

$ ls -l .htaccess
-rwxr-xr-x .htaccess

编辑:

我接受了Lanzz的建议,并在.htaccess 文件添加了胡言乱语,发现 .htaccess 文件没有读取。

最佳回答

为了实现这项工作,我在 /etc/apache2/httpd.conf (安装阿帕奇时默认为零长度文件) 中添加了以下内容,然后重新启动阿帕奇。 现在, Options - Indexes .htaccess 文件里, 将按需要工作。 这是最起码的操作要求 :

/etc/pache2/httpd.conf:

<VirtualHost *:80>
        DocumentRoot /var/www
        <Directory / >
        </Directory>
</VirtualHost>

lanzz 建议在.htaccess 文件上添加一条胡言乱语,看看阅读该词是否有助于诊断问题。

请注意 AllowOveride 默认为 All , per < a href=> "https://stackoverflow.com/uss/483349/evan-mulawski>>>>Evan Mulawski s 评论,因此上述最起码的 httpd.conf 行不需要。

问题回答

您应该检查 Apache 配置是否允许执行.ht 访问 。 在您的虚拟主机配置中, 应该有一个行 :

Allow 覆盖全部

如果没有,这就是为什么.ht获取权没有生效的原因。

我也有同样的问题。 我当时使用虚拟主机, 所以我修改了 httpd- vhosts. conf, 所以如果你使用这个可以帮助

在哪里配置主机引用文件的目录标签与文档 root 相同

<VirtualHost *:8080>
ServerName somelocalserver
DocumentRoot "C:/Websites/htdocs/yoursite"
<Directory "C:/Websites/htdocs/yoursite">
    Options FollowSymLinks
    AllowOverride All
</Directory>

我需要 Allowoverride all 来识别.httaccess 文件。

编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑编辑

我还需要在目录标签本身中添加站点根路径。 即< code_ lt; 日志“ C:/ Websites/ htdocs/yoursites” & gt; 。 这是我使用的样本中的默认值 。

由于已没有 httpd.conf 文件, 您需要在 VPS 上做 :

  1. Go to /etc/apache2/sites-enabled/
  2. Do ls to find the file for the website you re looking for
  3. Edit the corresponding file with nano THE_CONF_FILE or with whatever editor you d like
  4. Change all AllowOverride None values that you see in different <Directory> ... </Directory>s to AllowOverride All
  5. 保存文件并关闭文件

  6. 现在您需要通过运行命令来启用模块重写 : sudo a2enmod 重写

  7. And finally to activate the new configuration, you need to run: service apache2 restart

它会像一个魅力现在工作!

万一你有

AllowOverride None

改为:

AllowOverride All

in your httpd.conf or in your default virtualhost file in in /etc/apache2/sites-available/...conf

I solved this problem on RHEL by editing file /etc/http/conf/httpd.conf I changed all

AllowOverride None

将 to

AllowOverride All

您也可以根据 RHEL 的命令检查 httpd. conf 允许上传

grep -i AllowOverride /etc/conf/conf/httpd.conf

此外,除了将 允许 Override 全部更改为 vhost 配置文件外, 您可能需要在. httaccess 文件的开头添加以下内容 :

RewriteEngine On
RewriteBase /

否则,可能仍然无法发现重写或重写。

一个 s htaccess 文件没有被读取的另一个原因是 现有的 htaccess 强制执行 HTPS 301 重定向, 即浏览器会重新定位缓存, 如果虚拟主机配置不正确, 则会遇到问题 。 完整解释如下 。

如果您在 Apache 和 XAMPP 中设置虚拟主机, 例如, 如果您第一次在 Apache 和 XAMPP 中设置虚拟主机主机的 URL, 如果您有 HTPS 301 重定向的已有 htaccess 文件, 您的浏览器会被重定向到您的虚拟主机的 HTPS 版本。 但是可能会出现一个问题。 如果您没有为所涉域名建立 :: 433 虚拟主机, 在您的 Apache vhosts config 文件中, Apache 将默认使用列出的第一个虚拟主机 。

取决于默认虚拟主机的内容, 可能无法区分正在发生的事情, 用户会疯狂地试图确定为什么对 htaccess 文件的更改不再被处理 。

一旦您确定正在发生的事情, 工作选择就是禁用 HTTPS 重定向, 重新启用并重试, 而不使用 HTPS 。 真正的解决方案是完成一个包含证书的完整虚拟主机443 设置 。





相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签