Nginx Rewrite to Previous Directory

Posted by ThinkBohemian on Server Fault See other posts from Server Fault or by ThinkBohemian
Published on 2010-05-04T01:51:30Z Indexed on 2010/05/04 1:59 UTC
Read the original article Hit count: 318

Filed under:
|
|

I am trying to move my blog from blog.example.com to example.com/blog to do this I would rather not move anything on disk, so instead i changed my nginx configuration file to the following:

location /blog {
if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
}
    root /home/demo/public_html/blog.example.com/current/public/;
    index  index.php index.html index.html;
        passenger_enabled off;
        index index.html index.htm index.php;
        try_files $uri $uri/ @blog;
}

This works great but when i visit example.com/blog nginx looks for:

/home/demo/public_html/blog.example.com/current/public/blog/index.php 

instead of

/home/demo/public_html/blog.example.com/current/public/index.php

Is there a way to put in a rewrite rule so that I can have the server automatically take out the /blog/ directory?

something like ?

location /blog {
        rewrite \\blog\D  \;
    }

© Server Fault or respective owner

Related posts about nginx

Related posts about Wordpress