Apache2 htaccess 问题

Apache2 htaccess 问题

我目前无法让 Apache2 识别文件.htaccess。我目前在自己的机器上本地运行服务器以进行测试。我可以毫无问题地加载我的索引页,但每当我导航到与文件中的模式匹配的页面时,我都会收到 404 错误。这是我的文件和文件.htaccess的示例。default.conf.htaccess

default.conf

NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/  
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www/>   
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    Require all granted
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined
ServerSignature On

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

.htaccess

# Prevent Directoy listing 
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI}  !index\.php/?  [NC]
RewriteCond %{REQUEST_URI}  ^/([^/]+)/?.*/?  [NC]
RewriteRule ^(.*)  /api/index.php?/$1     [QSA,P,L]

从中可以看出,default.conf我将 AllowOverride 设置为 All,这通常是最常见的问题。我还启用了正确的 Apache 模块。此外,我也不认为这是权限问题。我查看了大量 Server Fault 和 Stack Overflow 帖子,但仍然无济于事。我还遗漏了什么吗?任何帮助都将不胜感激。

更新: 这是我的重写日志的转储:

[Sun Mar 09 00:07:45.752577 2014] [rewrite:trace3] [pid 10168] mod_rewrite.c(468): [client 127.0.0.1:37380] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b663e058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] add path info postfix: /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/v1 -> /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/v1/i/login, referer: http://localhost/login.php
[Sun Mar 09 00:07:45.752608 2014] [rewrite:trace3] [pid 10168] mod_rewrite.c(468): [client 127.0.0.1:37380] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b663e058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] strip per-dir prefix: /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/v1/i/login -> v1/i/login, referer: http://localhost/login.php
[Sun Mar 09 00:07:45.752614 2014] [rewrite:trace3] [pid 10168] mod_rewrite.c(468): [client 127.0.0.1:37380] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b663e058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] applying pattern '^(.*)' to uri 'v1/i/login', referer: http://localhost/login.php
[Sun Mar 09 00:07:45.752630 2014] [rewrite:trace2] [pid 10168] mod_rewrite.c(468): [client 127.0.0.1:37380] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b663e058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] rewrite 'v1/i/login' -> '/api/index.php?/v1/i/login', referer: http://localhost/login.php
[Sun Mar 09 00:07:45.752636 2014] [rewrite:trace3] [pid 10168] mod_rewrite.c(468): [client 127.0.0.1:37380] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b663e058/initial] split uri=/api/index.php?/v1/i/login -> uri=/api/index.php, args=/v1/i/login, referer: http://localhost/login.php
[Sun Mar 09 00:07:45.752641 2014] [rewrite:trace2] [pid 10168] mod_rewrite.c(468): [client 127.0.0.1:37380] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b663e058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] escaped URI in per-dir context for proxy, /api/index.php -> /api/index.php, referer: http://localhost/login.php
[Sun Mar 09 00:07:45.752648 2014] [rewrite:trace2] [pid 10168] mod_rewrite.c(468): [client 127.0.0.1:37380] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b663e058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] forcing proxy-throughput with http://localhost/api/index.php, referer: http://localhost/login.php
[Sun Mar 09 00:07:45.752653 2014] [rewrite:trace1] [pid 10168] mod_rewrite.c(468): [client 127.0.0.1:37380] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b663e058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] go-ahead with proxy request proxy:http://localhost/api/index.php?/v1/i/login [OK], referer: http://localhost/login.php
[Sun Mar 09 00:08:08.009404 2014] [rewrite:trace3] [pid 10158] mod_rewrite.c(468): [client 127.0.0.1:37389] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b6640058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] strip per-dir prefix: /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/index.php -> index.php
[Sun Mar 09 00:08:08.009460 2014] [rewrite:trace3] [pid 10158] mod_rewrite.c(468): [client 127.0.0.1:37389] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b6640058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] applying pattern '^(.*)' to uri 'index.php'
[Sun Mar 09 00:08:08.009473 2014] [rewrite:trace1] [pid 10158] mod_rewrite.c(468): [client 127.0.0.1:37389] 127.0.0.1 - - [localhost/sid#b63dbc90][rid#b6640058/initial] [perdir /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/] pass through /media/lnendza/Storage/workspace/CheckMate/Heffalump/site/api/index.php

从日志来看,一切似乎都正常。当我获取它返回的 URL ( http://localhost/api/index.php?/v1/i/login) 并将其放入浏览器中时,我可以正常进行操作。我希望这有助于进一步诊断我的问题。

答案1

在阅读了有关配置选项的更多信息后,我发现我的问题是由于没有在 Apache 中设置 mod_proxy 造成的。启用它后,我就可以继续了。这似乎是我的一个小疏忽,但希望这能对将来的某人有所帮助。

相关内容