.htaccess RewriteRule 添加驱动路径到 URL [英] .htaccess RewriteRule adds drive path to URL
问题描述
我在 Win7 机器上使用安装在 C: 上的 Zend Server CE (v.5.1.0).我通过添加以下内容向 httpd.conf 添加了一个项目:
I am using Zend Server CE (v.5.1.0) installed on C: on a Win7 machine. I have added one project to httpd.conf by adding:
Alias /project "D:\Homepages\project"
<Directory "D:\Homepages\project">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
我在 project 目录中的 .htaccess 文件包含以下内容:
My .htaccess file in the project directory contains the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^/\w*\.(css|js) [NC]
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
现在问题来了;如果我去
Now to the problem; if I go to
http://localhost/project/index.php
似乎一切正常.我到达 index.php 文件并获取我的内容.但是,如果我转到会触发 RewriteRule 的任何其他页面,它似乎正在添加目录路径.FireFox 输出以下未找到消息:
everything seems to be working fine. I reach the index.php file and get my contents. However, if I go to any other page that would trigger the RewriteRule, it seems to be adding the directory path. FireFox outputs the following Not Found message:
在此服务器上找不到请求的 URL/Homepages/project/index.php.
The requested URL /Homepages/project/index.php was not found on this server.
我试图在这里找到类似的问题/答案,但失败了.任何的想法?附言.我接受答案可能会延迟,因为我会出去一段时间出差.
I tried to find a similar question/answer here, but failed. Any idea? Ps. Me accepting of an answer might be delayed as I will be out for a while on an errand.
推荐答案
最后一行是这样的:
RewriteRule ^.*$ /index.php [NC,L]
但是我认为这是无限循环所以我建议改为:
However I think this is infinite loop so I would suggest this rule instead:
RewriteCond %{THE_REQUEST} !\s/index.php [NC]
RewriteCond %{REQUEST_URI} !^/index.php [NC]
RewriteRule . /index.php [L]
如果 index.php 已经是/index.php,它会阻止进入.
which prevents going to index.php if it is already /index.php.
这篇关于.htaccess RewriteRule 添加驱动路径到 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!