Lighttpd url.rewrite

发布于 2024-10-18 07:30:49 字数 575 浏览 7 评论 0原文

我希望在没有 .php 扩展名的情况下访问 /framework/ 文件夹中的所有 .php 文件。在网上搜索了一段时间后,我发现了这一点:

    url.rewrite = ( 
  "^/framework/([^?]*)(\?.*)?$" => "$1.php$2",
)

但是当然会产生后果,所以现在如果我访问 /framework/ (localhost/framework/) 它不会加载 index.php 文件 (localhost/framework/索引.php)。相反,它给出了 404。

我如何才能使 @ /framework/ 之外的任何文件夹加载目录index.php 文件?

所以喜欢

本地主机/框架/控制器/

将是

本地主机/framework/controller/index.php

等。

我对此很陌生,所以如果你能向我解释你做了什么,那就太好了。正如你所看到的,我在正则表达式方面并不是最好的。

I wanted all my .php files in my /framework/ folder to be accessed without the .php extension. After scouring the web for a while, I found this:

    url.rewrite = ( 
  "^/framework/([^?]*)(\?.*)?$" => "$1.php$2",
)

But of course there were consequences to that, so now if I access /framework/ (localhost/framework/) it doesn't load the index.php file (localhost/framework/index.php). Instead, it gives a 404.

How do I make it so that any folder beyond and @ /framework/ to load the directories index.php file?

So like

localhost/framework/controller/

would be

localhost/framework/controller/index.php

etc.

I'm rather new to this, so if you could explain to me what you did, that would be great. As you can see I'm not the best with regex.

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

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

发布评论

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

评论(1

蒗幽 2024-10-25 07:30:49

专门为带有尾部斜杠的路径添加一条规则:

url.rewrite = (
  "^/framework([^?]*/)(\?.*)?$" => "/framework$1index.php$2",
  "^/framework/([^?]*)(\?.*)?$" => "/framework/$1.php$2"
)

下面是正则表达式工作原理的详细说明:

^          // Match the beginning of the string
/framework // Match any string starting with "/framework"
(          // Open the first group ($1 in the right hand side)
  [^?]*    // Match zero or more characters that are not '?'
  /        // Ending in '/'
)          // Close the first group
(          // Open the second group ($2)
  \?       // Match a '?'
  .*       // Match zero or more characters
)          // Close the second group
?          // Match the second group exactly once or not at all
$          // Match the end of the string

Add a rule specifically for paths with a trailing slash:

url.rewrite = (
  "^/framework([^?]*/)(\?.*)?$" => "/framework$1index.php$2",
  "^/framework/([^?]*)(\?.*)?$" => "/framework/$1.php$2"
)

And here's a breakdown of how the regular expression works:

^          // Match the beginning of the string
/framework // Match any string starting with "/framework"
(          // Open the first group ($1 in the right hand side)
  [^?]*    // Match zero or more characters that are not '?'
  /        // Ending in '/'
)          // Close the first group
(          // Open the second group ($2)
  \?       // Match a '?'
  .*       // Match zero or more characters
)          // Close the second group
?          // Match the second group exactly once or not at all
$          // Match the end of the string
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文