url.rewrite-once 与 Kohana 和 urls

发布于 2024-09-03 13:56:57 字数 316 浏览 2 评论 0原文

目前我在 simple-hosts.conf 中有这样的设置:


url.rewrite-once = (
    ".*.(js|ico|gif|jpg|png|css|php|htm)(?.*)?$" => "$0",
    "/slapi" => "/slapi/index.php"
)

效果很好,但当我在查询字符串中有一个点时,上面的方法会失败:

?url=http://google.com

Currently I have this setup in our simple-hosts.conf:


url.rewrite-once = (
    ".*.(js|ico|gif|jpg|png|css|php|htm)(?.*)?$" => "$0",
    "/slapi" => "/slapi/index.php"
)

Works great, except the above fails when I have a dot in the query string:

?url=http://google.com

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

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

发布评论

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

评论(1

红衣飘飘貌似仙 2024-09-10 13:56:57

为什么不直接使用server.error-handler-404 = "/path/to/index.php"

但至于正则表达式本身,其中有许多未转义的字符。第二个 . 我假设您的意思是文字 .。如果是这样,您需要使用反斜杠 \. 对其进行转义。同样的情况也适用于?字符(我再次假设您的意思是字面意思?)。所以正则表达式应该是:

".*\\.(js|ico|gif|jpg|png|css|php|htm)(\\?.*)?$"

另外,您可以通过删除查询模式周围的问号来进一步改进它(我更喜欢这种语法,我发现它更容易阅读):

".*\\.(js|ico|gif|jpg|png|css|php|htm)(\\?.*|)$"

Why not just use the server.error-handler-404 = "/path/to/index.php"?

But as for the regex itself, you have many unescaped characters in there. The second . I'm assuming you mean as a literal .. If so, you need to escape it with a backslash \.. The same goes with the ? character (which again, I'm assuming you mean a literal ?). So the regex should be:

".*\\.(js|ico|gif|jpg|png|css|php|htm)(\\?.*)?$"

Plus, you could improve it even more by removing the question mark around the query pattern (I prefer this syntax, I find it easier to read):

".*\\.(js|ico|gif|jpg|png|css|php|htm)(\\?.*|)$"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文