.htaccess 限定符问题
有谁知道这个重写规则有什么问题吗?
RewriteRule ^example/?(.*)/?(.*)/?(.*)$ example.php?id=$1&ud=$2&ed=$3 [QSA,L]
难道不应该通过检测 ?
作为条件来工作吗?
编辑 好的,让我重新表述一下我的问题。
如果 $1
- $3
为空,如何让 Apache 忽略它,而直接转到 example.php?
例如,而不是 3 行:
RewriteRule ^example/(.*)/(.*)/(.*)$ example.php?id=$1&ud=$2&ed=$3 [QSA,L]
RewriteRule ^example/(.*)/(.*)$ example.php?id=$1&ud=$2 [QSA,L]
RewriteRule ^example/(.*)$ example.php?id=$1 [QSA,L]
我需要一行来解决所有 3 个或更多问题。
Does anyone know what the problem is with this rewrite rule?
RewriteRule ^example/?(.*)/?(.*)/?(.*)$ example.php?id=$1&ud=$2&ed=$3 [QSA,L]
Shouldn't it work by detecting ?
as a conditional?
Edit OK, let me rephrase my question.
How do you get Apache to ignore $1
- $3
if it's empty, and just instead go to example.php?
For example, instead of 3 lines:
RewriteRule ^example/(.*)/(.*)/(.*)$ example.php?id=$1&ud=$2&ed=$3 [QSA,L]
RewriteRule ^example/(.*)/(.*)$ example.php?id=$1&ud=$2 [QSA,L]
RewriteRule ^example/(.*)$ example.php?id=$1 [QSA,L]
I need one line to solve all 3 or more.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
贪婪的考虑使您的规则相当于以下内容:
您可能想要这个:
根据您对问题所做的最近编辑,我将使用多个规则:
Greediness considerations make your rule equivalent to the following:
You probably want this instead:
Based on the recent edit you did to your question, I'd use multiple rules:
当然可以,但是反向引用仍然按顺序填充。如果第一个括号
(.*)
匹配空字符串,则$1
为空;没有办法让这个捕获被“跳过”。Sure, but backreferences are still filled in order. If the first parentheses
(.*)
match the empty string, then$1
is empty; there is no way to make this capture get "skipped".404 错误可能是由于缺少 RewriteEngine 造成的。要解决参数问题,请使用:
The 404 error could be caused by a missing RewriteEngine. To solve the problem with the parameters, use: