(LigHTTPd) RegExp 重写规则

发布于 2024-07-15 07:33:53 字数 961 浏览 6 评论 0原文

尽管我对正则表达式的经验很少,但我正在为我正在编写的一些 PHP 脚本编写一些自己的规则。 注:很少。

基本上我想将除少数几个以外的所有 URL 作为参数传递给 index.php,重写数据库中定义为 slugs 的大多数 URL。

即:/admin、/config、/images、/lib 和/template 存在,但我不想被重写。 但其他一切,我想作为参数传递给index.php。

我目前正在这样做:

url.rewrite-once = (
    "^/(.*)$" => "/index.php?$1"
)

它与数据库段配合得很好,但它也会重定向上面列出的文件夹。 这些包含需要直接访问的文件,但我找不到任何描述如何从匹配中排除字符串的地方。

一旦我知道如何做到这一点,我就可以弄清楚其余的事情,但作为正则表达式的新手,我不知道从哪里开始。

任何帮助将不胜感激。

编辑: 从那时起,我就尝试了这些:

"^/(index\.php|admin|config|images|lib|template)" => "$0",

FF 报告了这些文件夹的无限重定向;

"^/(?!(admin|config|images|lib|template))(.*)$" => "$0"

不匹配除文件夹之外的所有内容;

"^/([^(admin|config|images|lib|template)]*)$" => "/index.php?$1"

再说一次,不重写任何东西;

"^/(.*)$" => "/index.php?$1"

重写所有内容,包括我不想重写的文件夹。

I'm writing some of my own rules for a few PHP scripts I'm writing, even though I have little experience with regexp. Note: little.

Basically I want to pass all URLs except a few as arguments to index.php, rewriting most URLs defined as slugs in a database.

ie: /admin, /config, /images, /lib and /template exists, but I do not want to be rewritten.
But everything else, I want passed as arguments to index.php.

I'm doing this currently with:

url.rewrite-once = (
    "^/(.*)$" => "/index.php?$1"
)

Which works beautifully with the database slugs, however it also redirects the folders listed above. These contain files needed to be directly accessed, but I can't find anywhere describing how to exclude strings from a match.

Once I know how to do this, I can figure out the rest, but being new to regexp I don't know where to start.

Any help would be greatly appreciated.

Edit:
I've since given these a shot:

"^/(index\.php|admin|config|images|lib|template)" => "$0",

For which FF reports an endless redirect for those folders;

"^/(?!(admin|config|images|lib|template))(.*)$" => "$0"

Doesn't match everything but the folders;

"^/([^(admin|config|images|lib|template)]*)$" => "/index.php?$1"

Again, doesn't rewrite anything;

"^/(.*)$" => "/index.php?$1"

Rewrites everything, including the folders which I don't want rewritten.

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

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

发布评论

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

评论(2

小情绪 2024-07-22 07:33:53

我似乎已经通过以下表达式实现了我正在寻找的内容:

"^/(?!(index\.php|admin|config|images|lib|template)).*$" => "/index.php?$0"

然后我只是

trim( $_SERVER['argv'] ,"/")

在index.php中获取slug。

I seem to have achieved what I was looking for with the following expression:

"^/(?!(index\.php|admin|config|images|lib|template)).*$" => "/index.php?$0"

I then just

trim( $_SERVER['argv'] ,"/")

in index.php to get the slug.

何以畏孤独 2024-07-22 07:33:53

尝试这个:

url.rewrite-once = (
    "^/(index\.php|admin|config|images|lib|template)" => "$0",
    "^/(.*)$" => "/index.php?$1"
)

Try this:

url.rewrite-once = (
    "^/(index\.php|admin|config|images|lib|template)" => "$0",
    "^/(.*)$" => "/index.php?$1"
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文