Nginx rewrite rule for favicon.ico files
Mark Alan
varia at e-healthexpert.org
Fri Aug 31 13:14:21 UTC 2012
On Fri, 31 Aug 2012 06:28:39 -0400 (EDT), "nexon"
<nginx-forum at nginx.us> wrote:
> Nginx rewrite rules for favicon.ico for multiple subdomains.
>
> In nginx /etc/sites-avaliable/vhost_config_file, I have the following
> rewrite rules for serving multiple subdomains with their favicon.ico
> files:
>
>
>
> if ($host = example1.example.com){
> rewrite ^/favicon.ico$ /favicon_example.ico break;
> }
>
> if ($host = example2.example.com){
> rewrite ^/favicon.ico$ /favicon_example.ico break;
> }
>
> if ($host = example3.example.com){
> rewrite ^/favicon.ico$ /favicon_example.ico break;
> }
>
>
> Please, how can I make this simple operation by adding **ONE GENERAL
> REWRITE RULE**:
>
> That rule must do:
>
> 1.For subdomains example1,example2... to check in
> location /images/$host.ico is there a favicon_example.ico file and
> serve it.
>
> 2.If there is no such file, than to serve just a plain favicon.ico
> file.
Would this help? [note: from memory, not tested]
location = /favicon.ico {
try_files /images/$server_name.ico /favicon.ico =204;
}
M.
More information about the nginx
mailing list