Apache没有运行我的PHP索引脚本


Apache isn't running my PHP index script

如果我决定把它放在我的.htaccess文件中:

IndexIgnore */*
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page_request=$1 [QSA,L]

该网站运行良好。然后我决定mv index.php subdir/index.php,所以我将最后一行更改为以下内容:

RewriteRule ^(.*)$ /subdir/index.php?page_request=$1 [QSA,L]

我看到的只是一个Apache目录列表。我做错了什么?这可能是一个非常简单的解决方案,但我的资源没有出现任何东西。

困扰我的是这应该有效。直观而自然地认为所需要的只是 更改index.php的文件位置 .

编辑

我试过RewriteBaseRewriteCond %{REQUEST_URI} !/subdir/index.php.两者都没有奏效。

您是否尝试过启用重写日志记录?尝试将其添加到您的虚拟主机:

RewriteLogLevel 3
RewriteLog "/usr/local/var/apache/logs/rewrite.log"

您发布的规则似乎对我来说很好...

编辑:

好的,我能够在Mac上复制该问题,并发现这就是您需要的:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]
RewriteCond %{REQUEST_URI} /
RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]

问题是,当你只是去http://localhost/ %{REQUEST_FILENAME}没有值时。可能有一种方法可以将这些规则合并为一个,但我还没有弄清楚。

编辑 2:

我刚刚尝试了这个,它也起作用了:

DirectoryIndex subdir/index.php
RewriteEngine On   
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]

但是,它没有任何 page_request $_GET 变量值的内容,因此您必须在代码中处理这种情况。

这是有效的,因为你告诉 Apache 在子目录中查找索引页而不是当前目录。

尝试删除斜杠。

RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]

RewriteRule ^(.*)$ ./subdir/index.php?page_request=$1 [QSA,L]

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/subdir/index.php 
RewriteRule (.*) /subdir/index.php?page_request=$1 [QSA,L]

使用这个:

 RewriteRule ^(.*)$ subdir/index.php?page_request=$1 [QSA,L]