使用 .htaccess 时如何使 mod_rewrite *不*执行主目录扩展
文件路径:/Users/user_name/Sites/example.com
可浏览位置:http://localhost/~user_name/example.com/
在子目录中 (chrome
)我得到了一个像这样的.htaccess
:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^rgba\((\d{1,3}%?,\s?\d{1,3}%?,\s?\d{1,3}%?,\s?[0-1]?\.?\d+)\)$ rgba.php?rgba=$1 [PT]
这与这样的请求匹配:
http://localhost/~user_name/example.com/chrome/rgba(255,255,255,0.5)
并且应该将请求重写为:
http://localhost/~user_name/example.com/chrome/rgba.php?rgba=(255,255,255,0.5)
我将rgba.php放在chrome
中目录。我仍然收到此错误消息:
The requested URL /Users/user_name/Sites/example.com/chrome/rgba.php was not found on this server.
我阅读了手册中有关主目录扩展和 [PT] 标志的部分,但这没有什么区别。
如果我放置一个指向 example.com 目录的虚拟主机,它就可以工作。我希望它能双向工作=P
那么我该怎么做呢?
我在 Mac OS X 上运行 Apache/2.2.15 (Unix)
编辑 对于用户 Sites
目录,AllowOverride
设置为 All
。如果不是的话,重写根本就不会起作用。
Filepath: /Users/user_name/Sites/example.com
Browseable at: http://localhost/~user_name/example.com/
In a child directory (chrome
) I got a .htaccess
like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^rgba\((\d{1,3}%?,\s?\d{1,3}%?,\s?\d{1,3}%?,\s?[0-1]?\.?\d+)\)$ rgba.php?rgba=$1 [PT]
This matches a request like:
http://localhost/~user_name/example.com/chrome/rgba(255,255,255,0.5)
and should rewrite the request to:
http://localhost/~user_name/example.com/chrome/rgba.php?rgba=(255,255,255,0.5)
I put the rgba.php in the chrome
directory. Still I get this error msg:
The requested URL /Users/user_name/Sites/example.com/chrome/rgba.php was not found on this server.
I read the part in the manual about Home directory expansion and the [PT] flag but it makes no difference.
If i put up a vhost pointing to the example.com
directory it works. I would like it to work both ways =P
So how do I do it?
I run Apache/2.2.15 (Unix) on a Mac OS X
EDITAllowOverride
is set to All
for the users Sites
directory. If it wasn´t the rewrite shouldn´t have worked at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
圣神真是令人沮丧。但我有它的工作。
我尝试了很多东西。我认为 RewriteRule 上的 PT 标志可以解决这个问题,但事实并非如此。
我仍然不知道如何停止主目录扩展,但我找到了一个解决方法。在
RewriteRule
之前,使用RewriteBase /~user_name/example.com/chrome/
。这会覆盖重写的前缀(来自我的配置的日志条目):更新
此解决方案在某种程度上起作用,但它似乎使重写引擎触发两次......一次用于内部重定向,然后再次触发。我最终像其他提交者一样使用了 VirtualHost。
Holy god that was frustrating. But I have it working.
I tried a bunch of stuff. I thought that the PT flag on the RewriteRule would fix it, but nope.
I still don't know how to stop the home directory expansion, but I figured out a workaround. Just before the
RewriteRule
, useRewriteBase /~user_name/example.com/chrome/
. This overrides the rewrite's prefix (log entry from my config):UPDATE
This solution works somewhat, but it appears to make the rewrite engine trigger twice... once for the internal redirect, and again afterwards. I ended up just using a VirtualHost like the other submitter.
允许覆盖您的主目录的配置文件。
Allow overrides in you configuration file for your home directories.
我花了半天的时间在这个问题上绞尽脑汁,我能找到的唯一解决方案是创建一个新的 VirtualHost,并将 DocumentRoot 设置为用户的主目录。
I spent half a day wracking my brains on this and the only solution I could find was to create a new VirtualHost with the DocumentRoot set to the user's home directory.