Url rewriting Lighttpd url.rewrite
我希望在不使用.php扩展名的情况下访问/framework/文件夹中的所有.php文件。在网上搜索了一段时间后,我发现:Url rewriting Lighttpd url.rewrite,url-rewriting,lighttpd,Url Rewriting,Lighttpd,我希望在不使用.php扩展名的情况下访问/framework/文件夹中的所有.php文件。在网上搜索了一段时间后,我发现: url.rewrite = ( "^/framework/([^?]*)(\?.*)?$" => "$1.php$2", ) 当然,这会带来一些后果,所以现在如果我访问/framework/localhost/framework/它不会加载index.php文件localhost/framework/index.php。相反,它给出了404 我如何使任
url.rewrite = (
"^/framework/([^?]*)(\?.*)?$" => "$1.php$2",
)
当然,这会带来一些后果,所以现在如果我访问/framework/localhost/framework/它不会加载index.php文件localhost/framework/index.php。相反,它给出了404
我如何使任何超出和@/framework/的文件夹加载directories index.php文件
很像
localhost/framework/controller/
会是
localhost/framework/controller/index.php
等等
我是个新手,所以如果你能向我解释一下你做了什么,那就太好了。正如您所看到的,我不是正则表达式的最佳选择。添加一条规则,专门用于带有尾随斜杠的路径:
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
添加专门针对带有尾随斜杠的路径的规则:
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
啊,为什么谢谢你,你做得很好解释:非常感谢。啊,为什么谢谢你,你做得很好解释:非常感谢。