.htaccess RewriteRule 将驱动器路径添加到 URL
我正在使用安装在 Win7 计算机上的 C: 上的 Zend Server CE (v.5.1.0)。我已将一个项目添加到 httpd.conf 中,方法是添加:
Alias /project "D:\Homepages\project"
<Directory "D:\Homepages\project">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
project 目录中的 .htaccess 文件包含以下内容:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^/\w*\.(css|js) [NC]
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
现在解决问题;如果我去
一切似乎都工作正常。我到达 index.php 文件并获取我的内容。 但是,如果我转到任何其他会触发 RewriteRule 的页面,它似乎会添加目录路径。 FireFox 输出以下未找到消息:
在此服务器上找不到请求的 URL /Homepages/project/index.php。
我试图在这里找到类似的问题/答案,但失败了。有什么想法吗? 诗。我接受答案可能会延迟,因为我要出去办事一段时间。
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>
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
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:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要设置RewriteBase指令;否则,mod_rewrite 会自动并默认将文件路径添加到生成的重写规则中。
来自: http://httpd.apache.org/docs/2.0/mod/mod_rewrite .html
You need to set the RewriteBase directive; otherwise, mod_rewrite automatically, and by default, prepends the file path to the resulting rewrite rule.
From: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
你的最后一行是这样的:
但是我认为这是无限循环,所以我建议改用这个规则:
如果它已经是/index.php,它会阻止转到index.php。
Have your last line like this:
However I think this is infinite loop so I would suggest this rule instead:
which prevents going to index.php if it is already /index.php.