nginx: redirect root to subdirectory while maintaining url

I have an nginx setup with folder structure like this:

- www
|- splash
|- blog

www is the root folder.

I would like to redirect users who access http://mysite.com to the splash folder.

But I don't want the URL in the address bar to change to http://mysite.com/splash.

The URL in the address bar should still be http://mysite.com.

This rule should only apply when user accesses the root folder.

Meanwhile accessing the blog folder will be as usual via: http://mysite.com/blog.

How do I achieve this? So far my conf is as follow: (they don't work btw)

location / {
    root /www;
    index index.html;
}

location = / {
    root /www/splash;
    index index.html;
}

Cheers!

1 Reply

keep you second config and remove the first.

for blog do a location /blog … with a root change

look up the meaning of = with location and see if this is really what you want.

also look what alias means in nginx configs.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct