【问题标题】:Apache ignores my .htaccess filesApache 忽略我的 .htaccess 文件
【发布时间】:2013-03-21 17:11:23
【问题描述】:

Apache 完全忽略了我的 .htaccess 文件,无论我在其中写什么,它都不会读取它。

  • 重写模组已启用
  • AllowOverride 设置为全部

虚拟主机:/etc/apache2/sites-enabled/example.com

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName example.com
    ServerAlias *.example.com
    DocumentRoot /var/www/example.com

    <Directory /var/www/example.com>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

</VirtualHost>

htaccess 文件:/var/www/example.com/.htaccess

RewriteEngine on
RewriteRule ^hjalp/$ /index.php?page=help

所有与此相关的问题似乎总是可以通过启用 mod rewrite 或将 AllowOverride 更改为 All 而不是 None 来解决。但这对我没有任何作用,是的,我已经重新加载并重新启动了 apache。 (Ubuntu 12.10 "Quantal Quetzal" Minimal x64, Apache/2.2.22)

我该如何解决这个问题?

编辑: 我从来没有真正发现这背后的问题,但干净的重新安装(再次)解决了问题。

【问题讨论】:

  • 到目前为止,您的配置和 htaccess 看起来还不错。究竟会发生什么?如果您有权访问日志文件,请查看/var/log/apache2/ 目录并查看请求的内容(access 文件)以及可能发生的错误(error 文件)。日志行中有一个时间戳,您可以在其中将访问/错误消息与最新请求相关联。
  • 当我尝试访问 /hjalp/ 时,我只是得到一个 404。apache 错误日志也不是很有帮助,他们只是说“文件不存在:/var/www/example.com /hjalp"
  • 您确定 mod_rewrite 已启用吗? ls /etc/apache2/mods-enabled/ | grep rewrite
  • rewrite.load ... 所以是的,mod_rewrite 也是根据 phpinfo() 加载的。一定有我遗漏的东西,这是使用默认配置文件的全新安装...
  • 你启用了 mod_alias 和 mod_userdir 吗? httpd.apache.org/docs/2.0/misc/rewriteguide.html#ToC1

标签: apache .htaccess


【解决方案1】:

试试

RewriteEngine on
RewriteRule ^hjalp/$ index.php?page=help

没有斜线它对我有用

【讨论】:

  • 我拥有的RewriteRule在开发环境中工作,这个问题我相信与Apache有关。
  • 你试过不带斜线吗?
猜你喜欢
  • 2011-07-09
  • 2019-04-15
  • 1970-01-01
  • 2012-09-20
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 2018-06-09
相关资源
最近更新 更多