Dmitry Velichko
Dmitry Velichko

Reputation: 41

nginx rewrite rules

I'm trying to implement nginx rewrite rules for the following situtation : - Request /testfa/styles/style.css should be redirected to /testfa/templates/styles/style.css I've enabled rewrite logging for my server, created following rules:

location /testfa {     
  rewrite ^/styles/(.+)?$ /testfa/templates/styles/$1 last;
}

but when I'm trying to perform request, I'm getting 404 error from server, and log file doesn't contain any info about rewriting, only following message:

open() "......../testfa/styles/style.css" failed (2: No such file or directory)

What is the correct way to perform such a rewrite for nginx ?

Upvotes: 4

Views: 20659

Answers (1)

Glavić
Glavić

Reputation: 43552

location /testfa/ {
    rewrite ^/testfa/styles/(.+)$ /testfa/templates/styles/$1 last;
}

does this work for you ?

my tested virtual >

server {
    listen          ...ip...:80;
    server_name     sub.domain.com;
    root            /usr/local/www/test;
    error_log       /usr/local/www/test/error_debug.log debug;

    rewrite_log     on;

    location /testfa/ {
        rewrite ^/testfa/styles/(.+)$ /testfa/templates/styles/$1 last;
    }
}

this works. even log has reported :

2011/11/25 01:06:52 [notice] 35208#0: *456705 rewritten data: "/testfa/templates/styles/test.css", args: "", client: IP, server: sub.domain.com, request: "GET /testfa/styles/test.css HTTP/1.1", host: "sub.domain.com"

Upvotes: 2

Related Questions