mod_rewrite的问题做单个php文件

时间:2013-04-19 05:22:14

标签: php apache mod-rewrite

我将所有请求定向到一个单独的php文件时遇到问题。我之前使用过设置。

C:/path/app/.htaccess

中的配置
DirectoryIndex  disabled

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ web/index.php    [QSA,L]

错误记录

[Fri Apr 19 07:04:04.582078 2013] [rewrite:trace3] [pid 4804:tid 1284] mod_rewrite.c(466): [client 127.0.0.1:65174] 127.0.0.1 - - [127.0.0.1/sid#238bf48][rid#2d9e170/initial] [perdir C:/path/app/] strip per-dir prefix: C:/path/app/ -> 
[Fri Apr 19 07:04:04.582078 2013] [rewrite:trace3] [pid 4804:tid 1284] mod_rewrite.c(466): [client 127.0.0.1:65174] 127.0.0.1 - - [127.0.0.1/sid#238bf48][rid#2d9e170/initial] [perdir C:/path/app/] applying pattern '^(.*)$' to uri ''
[Fri Apr 19 07:04:04.582078 2013] [rewrite:trace2] [pid 4804:tid 1284] mod_rewrite.c(466): [client 127.0.0.1:65174] 127.0.0.1 - - [127.0.0.1/sid#238bf48][rid#2d9e170/initial] [perdir C:/path/app/] rewrite '' -> 'web/index.php'
[Fri Apr 19 07:04:04.582078 2013] [rewrite:trace3] [pid 4804:tid 1284] mod_rewrite.c(466): [client 127.0.0.1:65174] 127.0.0.1 - - [127.0.0.1/sid#238bf48][rid#2d9e170/initial] [perdir C:/path/app/] add per-dir prefix: web/index.php -> C:/path/app/web/index.php
[Fri Apr 19 07:04:04.582078 2013] [rewrite:trace1] [pid 4804:tid 1284] mod_rewrite.c(466): [client 127.0.0.1:65174] 127.0.0.1 - - [127.0.0.1/sid#238bf48][rid#2d9e170/initial] [perdir C:/path/app/] internal redirect with C:/path/app/web/index.php [INTERNAL REDIRECT]

文件C:/path/app/web/index.php存在且只是phpinfo()。

<?php

phpinfo();

如果我获得了日志权限,重定向正在按预期工作,但我仍然得到404.

有什么想法可能会出现问题吗?

1 个答案:

答案 0 :(得分:1)

您的重写规则需要知道文件夹库(默认情况下是Web服务器根目录)。

因此,您需要在RewriteBase /app/

之后立即设置RewriteEngine on
RewriteEngine on
RewriteBase /app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ web/index.php    [QSA,L]