Nginx rewrite base url

nginxregexrewrite

I would like the root url

http://www.example.com

to redirect to

http://www.example.com/something/else

This is because some weird WP plugin always sets a cookie on the base url, which doesn't let me cache it.

I tried this directive:

location / {
    rewrite  ^  /something/else  break;
}

But 1) there is no redirect and 2) pages start shooting more than 1,000 requests to my server. With this one:

 location / {
        rewrite  ^  http://www.example.com/something/else  break;
    }

Chrome reports a redirect loop.

What's the correct regexp to use?

Best Answer

You really want to be matching exactly the root URL in your location block, not "absolutely everything":

location = / {
    rewrite ^ /something/else break;
}