(LigHTTPd) RegExp 重写规则
尽管我对正则表达式的经验很少,但我正在为我正在编写的一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我似乎已经通过以下表达式实现了我正在寻找的内容:
然后我只是
在index.php中获取slug。
I seem to have achieved what I was looking for with the following expression:
I then just
in index.php to get the slug.
尝试这个:
Try this: