When you put your website in maintenance mode, it’s a good idea to return a HTTP 503 error code to the client.
This code indicates that “the server is currently unable to handle the request due to a temporary overloading or maintenance of the server”.
The 503 code is used to avoid crawlers or caching proxy use the maintenance page as the new valid content for the request. You certainly don’t want Google save this content in his search index as the content of your website
To achieve this we will use a rewrite rule in lighttpd to redirect all requests to a single PHP script which will return a 503 error code and print an informative message.
url.rewrite = ( "" => "/maintenance.php" )
This configuration will redirect any request to maintenance.php script.
If you need to serve an image in your maintenance page, you have to add another rule to the rewrite process like that :
url.rewrite = ( "upgrading.png" => "$0", "" => "/maintenance.php" )
It might be usefull to let admins or developers access the website during the maintenance.
For that, you can disable the maintenance rewrite rule for certain IP addresses :
$HTTP["remoteip"] != “192.168.1.42″ {
url.rewrite = ( "upgrading.png" => "$0",
"" => "/maintenance.php" )
}
<?php
header("HTTP/1.1 503 Service Unavailable");
?>
We're currently upgrading our servers...
This entry was written by , posted on July 22, 2008 at 2:28 am, filed under http and tagged lighttpd, php. Leave a comment or view the discussion at the permalink.
If you want to redirect visitors that access your website without the ‘www’, you can use mod_redirect with the following syntax:
$HTTP[”host”] =~ “^lescampeurs\.org” {
url.redirect = (
”^/(.*)$” => “http://www.lescampeurs.org/$1″
)
}
Links:
This entry was written by , posted on June 30, 2008 at 11:47 pm, filed under http and tagged lighttpd. Leave a comment or view the discussion at the permalink.
If you’re using SVN to control your web application, your certainly need to deny access to .svn sub-directories.
<DirectoryMatch "^/.*/\.svn/">
Order allow,deny
Deny from all
</DirectoryMatch>
$HTTP["url"] =~ "/\.svn/" {
url.access-deny = ( "" )
}
This entry was written by , posted on May 28, 2008 at 7:17 am, filed under http and tagged apache, lighttpd, svn. Leave a comment or view the discussion at the permalink.
server.modules += ( "mod_redirect" )
$HTTP["host"] =~ "^domain\.com$" {
url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" )
}
$HTTP["host"] =~ "^www\.domain\.com$" {
url.redirect = ( "^/(.*)" => "http://domain.com/$1" )
}
$SERVER["socket"] == ":80" {
$HTTP["host"] =~ "(.*)" {
url.redirect = ( "^/(.*)" => "https://%1/$1" )
}
}
$HTTP["host"] =~ "^www1\.domain\.com" {
url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" )
}
Lets say that you want to redirect http://www.domain.com/party to http://blog.domain.com/party while you have a mod_rewrite rule on www.domain.com that redirect all URLs to a controller (“^(.*)$” => “/index.php$1″).
Your redirect will not work because mod_rewrite always execute before redirect rules. To bypass this, you need to use the $0 as the rule target to pass URLs through unmangled.
e.g.
url.redirect = ( "^/party(.*)" => "http://blog.domain.com/party$1" ) url.rewrite-once = ( "^/party" => "$0" )
tested with lighttpd 1.4.x
This entry was written by , posted on May 6, 2008 at 12:56 pm, filed under http and tagged lighttpd. Leave a comment or view the discussion at the permalink.