SteveMustafa
SteveMustafa

Reputation: 619

nginx rewrite transparent rewrite from root to subdomain

So I want my default landing page to be www.example.com/blog rather than www.example.com, however, I wouldn't want a rewrite, just have www.example.com point to www.example.com/blog

For the life of me, I can't get the rewrites to work right.

I tried

location / {
    rewrite ^(/)$/blog permanent;
}

I'm obviously floundering but I WILL learn regex as a result.

So can someone please help me fixt this regex?

Upvotes: 0

Views: 788

Answers (2)

Arthur Borsboom
Arthur Borsboom

Reputation: 341

Will this work?

rewrite ^$ /blog permanent;

Or this?

location = / {
    rewrite ^ /blog permanent;
}

Upvotes: 0

avatarofhope2
avatarofhope2

Reputation: 172

I understand regex, but am not familiar with nginx

I think you might want something like this instead:

rewrite ^\/$ /blog

meaning anything that starts and ends with a forward slash, replace with /blog. you may need to escape the forward slash in "/blog" too:

rewrite ^\/$ \/blog

Upvotes: 1

Related Questions