Lighttpd url.rewrite

Fel*_*mbc 1 lighttpd url-rewriting

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

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

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

如何让它超出任何文件夹和@/framework /来加载目录index.php文件?

所以喜欢

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

将会

本地主机/框架/控制器/ index.php的

等等

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

Jas*_*erk 10

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

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

这里是正则表达式如何工作的细分:

^          // 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
Run Code Online (Sandbox Code Playgroud)