使用 .htaccess 时如何使 mod_rewrite *不*执行主目录扩展

发布于 2024-10-07 05:39:41 字数 1069 浏览 5 评论 0原文

文件路径:/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

EDIT
AllowOverride is set to All for the users Sites directory. If it wasn´t the rewrite shouldn´t have worked at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往事风中埋 2024-10-14 05:39:42

圣神真是令人沮丧。但我有它的工作。

我尝试了很多东西。我认为 RewriteRule 上的 PT 标志可以解决这个问题,但事实并非如此。

我仍然不知道如何停止主目录扩展,但我找到了一个解决方法。在 RewriteRule 之前,使用 RewriteBase /~user_name/example.com/chrome/。这会覆盖重写的前缀(来自我的配置的日志条目):

<SNIP> (2) [perdir /Users/colin/Sites/ajaxtest/] trying to replace prefix /Users/colin/Sites/ajaxtest/ with /~colin/ajaxtest/

更新

此解决方案在某种程度上起作用,但它似乎使重写引擎触发两次......一次用于内部重定向,然后再次触发。我最终像其他提交者一样使用了 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, use RewriteBase /~user_name/example.com/chrome/. This overrides the rewrite's prefix (log entry from my config):

<SNIP> (2) [perdir /Users/colin/Sites/ajaxtest/] trying to replace prefix /Users/colin/Sites/ajaxtest/ with /~colin/ajaxtest/

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.

命比纸薄 2024-10-14 05:39:42

允许覆盖您的主目录的配置文件。

Allow overrides in you configuration file for your home directories.

那小子欠揍 2024-10-14 05:39:41

我花了半天的时间在这个问题上绞尽脑汁,我能找到的唯一解决方案是创建一个新的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文