htaccess的重写规则增加了驱动器路径URL [英] .htaccess RewriteRule adds drive path to URL

查看:168
本文介绍了htaccess的重写规则增加了驱动器路径URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Zend服务器CE(v.5.1.0)安装在C:一个Win7的机器上。我已经增加了一个项目的的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>

我的的.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]

现在的问题;如果我去

HTTP://localhost/project/index.php

一切似乎是工作的罚款。我到达的的index.php 的文件,并让我的内容。 但是,如果我去,将触发重写规则任何其他页面,这似乎是增加的目录路径。火狐输出以下的未找到消息:

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:

所请求的网址/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]

这prevents去到index.php,如果它已经的index.php。

which prevents going to index.php if it is already /index.php.

这篇关于htaccess的重写规则增加了驱动器路径URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆