【问题标题】:.htaccess files not working on apache.htaccess 文件在 apache 上不起作用
【发布时间】:2013-12-16 20:35:25
【问题描述】:

/etc/apache2/sites-available/default.conf 内容如下:

<Directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>

我启用了 mod_rewrite

在 /var/www/sitename 下 我有我的 .htaccess 文件,内容如下:

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

然而,当访问 localhost/sitename/directory 时,我得到一个 404 错误

我在这里错过了什么?

【问题讨论】:

  • 开启大量调试,然后查看日志。
  • 对不起,我对此很陌生,不确定如何打开调试/检查日志。
  • tail -f /var/log/apache2/*.log 然后刷新浏览器。默认情况下应该启用日志记录。
  • 我希望指令
  • 我启用了日志,当我刷新时,我只收到一个访问日志,告诉我我收到 404 错误,因为找不到目录。似乎 apache 没有考虑我在 sitename 目录中的 .htaccess 文件。

标签: linux apache .htaccess mod-rewrite


【解决方案1】:

尝试在第一个RewriteCond 上方添加RewriteRule ^(directory)($|/) - [L],这样它将从RewriteRule 中排除该目录,您可以添加多个目录,方法是用| 分隔它们,例如RewriteRule ^(forum|extras)($|/) - [L]

这是一个例子:

RewriteEngine On
RewriteBase /

RewriteRule ^(directory)($|/) - [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l 

【讨论】:

  • 能不能用pastebin.com把整个apache配置文件放好?
  • 我想我看到了我的问题
  • 是的,您的 AllowOveride 设置为无。 :)
  • apache配置设置正确,/etc/apache2/sites-enabled/中应该有一个名为000-default.conf的文件。请在 pastebin.com 上发布
【解决方案2】:

对于使用 ubuntu 的人,我发现这个答案很完整。

https://askubuntu.com/a/48363

【讨论】:

  • 由于某些原因 apache 没有读取我的 default.conf 文件,所以我不得不更改 /etc/apache2/apache2.conf 下的设置
【解决方案3】:

试试这个 -

Options +FollowSymLinks
RewriteEngine on
RewriteRule process-id-(.*)\.htm$ process.php?id=$1 

【讨论】:

    猜你喜欢
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    • 2015-02-23
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多