.htaccess - Converting .htaccess to lighttpd for a subdirectory
问题描述
I'm a newbie and am trying to convert a htaccess to lighttpd format but everything I try doesn't work. I have a few rules for example.com and now I want to add a new subdirectory named /test and use htaccess rules just for that directory (is that even possible?). Anyway, here's the htaccess I want to convert:
Options +FollowSymlinks
RewriteRule ^.*\.(gif|png|jpe?g|bmp|css|js|swf|wav|avi|mpg|ttf|woff)$ - [NC,L]
RewriteRule ^dashboard/ - [R=403,L,NC]
RewriteRule ^admin/ - [R=403,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.sa$ index.php?sa=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?uri=$1 [PT,L]
Now, my guesswork solution was this, but it doesn't work and I don't understand how can I make it work:
$HTTP["url"] =~ "^/test" {
$HTTP["url"] !~ "^/(dashboard|admin)/" {
url.access-deny = ("")
}
url.rewrite-if-not-file = (
"^/(.*)$" => "/index.php?uri=$1",
"^/(.*/).sa$" => "index.php?sa=$1",
)
server.follow-symlink = "enable"}
Can anyone help? Thanks
解决方案
lighttpd 重写规则与完整的 url-path + query-string 匹配,而$HTTP["url"]
只是 url-path(是的,我可以看到这可能有点令人困惑)并且$HTTP["query-string"]
只是 query-string。
以下使用了 lighttpd 1.4.50(一年多前发布)中可用的一些语法。 lighttpd 的当前版本是 lighttpd 1.4.54。(例如,如果您使用的是 lightttpd 1.4.45,那么您的发行版会落后一点)
$HTTP["url"] !~ "^/(dashboard|admin)/" {
url.access-deny = ("")
}
$HTTP["url"] !~ "\.(?i:gif|png|jpe?g|bmp|css|js|swf|wav|avi|mpg|ttf|woff)$" {
url.rewrite-if-not-file = (
"^(/.*)\.sa(\?.*)?$" => "index.php?sa=$1${qsa}",
"" => "/index.php?uri=${url.path}${qsa}",
)
}
server.follow-symlink = "enable"
推荐阅读
- python - 这个列表理解有什么作用?
- javascript - 当对 2 个数组中的值求和时,如何限制新数组中的值?
- angular - 不使用表格元素但使用显示属性显示基于数组的表格
- database - 从 codeigniter 网站更新本地和 Web 数据库
- gremlin - AWS Neptune - gremlin 属性顺序
- php - 我的 Laravel 网站的元关键字问题
- ios - Firebase 控制台中未显示崩溃
- java - 在构造函数注释中使用 builder(lombok) 时出错
- xml - Header 和 Page1 之间有更多空间,但从 page2 开始是正确的
- html - 如何仅使用 CSS 使内容在滚动条下?