# Alias with variable sometimes works and sometimes returns 404

**URL:** <https://www.ruby-forum.com/t/alias-with-variable-sometimes-works-and-sometimes-returns-404/225728>\
**Category:** NGINX\
**Created:** [January 26, 2013, 1:57am UTC](https://www.ruby-forum.com/t/alias-with-variable-sometimes-works-and-sometimes-returns-404/225728 "2013-01-26T01:57:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [January 26, 2013, 1:57am UTC](https://www.ruby-forum.com/t/alias-with-variable-sometimes-works-and-sometimes-returns-404/225728/1 "2013-01-26T01:57:25Z")

</div>

I have the following in my server block:

```
set $filename wizard-min;
if($cookie_B) {
   set $filename $cookie_B;
}

location ~* "^/b/([a-f0-9]{10})$" {
   default_type application/javascript;
   alias /var/www/b/b-$filename.js;

   sub_filter_types application/javascript;
   sub_filter '%replace%' '$1';
}

```

I request it using curl:

curl -v ‘[http://server/b/0123456789](http://server/b/0123456789)’

sometimes it returns the file correctly, and sometimes it returns a 404.  
When it does return a 404, the error log says:  
“/var/www/b/0123456789” failed (2: No such file or directory)

Note that I’m testing this on a single server, and every request goes  
into  
the access log file, but some of them (20-30%) return a 404.

If I take out the variable from the alias line, the file returns  
correctly  
every time.

Any idea?

PS: Is there any way to get my code formatted correctly on this forum?

Posted at Nginx Forum:

> **[Alias with variable sometimes works and sometimes returns 404](https://forum.nginx.org/read.php?2,235587,235587#msg-235587)**
>
> I have the following in my server block: set $filename wizard-min; if($cookie\_B) { set $filename $cookie\_B; } location ~\* "^/b/(\[a-f0-9\]{10})$" { default\_type application/javascript;
