刚刚启动apache .htaccess重写到lighttpd转换

时间:2017-03-11 15:36:36

标签: php apache .htaccess mod-rewrite lighttpd

以下是来自apache的.htaccess文件。我在子目录中遇到404未找到错误,我确信它与我的重写有关。

Options -Indexes
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On

    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* file.php [L,QSA]

</IfModule>

这是我的lighttpd.conf重写

$HTTP["host"] =~ "www.example.com" {
url.rewrite           = ( "^(.*)$" => "$1.php" )
}

server.follow-symlink = "enable"

我知道&#34; $ 1.php&#34;不是正确的答案。它有点工作,但我不认为它有用。这里唯一的目的是帮助整理我想要做的事情。

1 个答案:

答案 0 :(得分:0)

有关

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

请参阅https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModRedirect

$HTTP["host"] == "example.com" {
    url.redirect = ( "^(.*)$" => "http://www.example.com$1" )
}

有关

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* file.php [L,QSA]

https://redmine.lighttpd.net/boards/2/topics/6459

对于!-f和!-d请参阅https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModRewrite

中的url.rewrite-if-not-file

对于QSA,使用lighttpd条件块匹配查询字符串,然后用%1替换,例如

$HTTP["querystring"] =~ "(.*)" {
  url.rewrite-if-not-file = ( "..." => "...&%1" )
} else {
  url.rewrite-if-not-file = ( "..." => "..." )
}