Rewrite root address to a subdirectory in nginx
I found help in the nginx irc chat.
Basically what I needed to do was use a return instead of rewrite. So I changed this:
location = / {
rewrite "^$" /wiki/Main_Page;
}
to this:
location = / {
return 301 http://www.example.com/wiki/Main_Page;
}
- Make sure "/wiki/Main_Page" can be successfully accessed
- Check in the server section, there are no global rewrite rules. Rewrite rules in server section will be executed before location section.
Using rewrite rules in location section like this:
location = / { rewrite "^.*$" /wiki/Main_Page break; }
Pay attention "break" here. Means break out the rewrite cycle.
If this page is located in backend server, here should use proxy_pass.
I prefer to use:
location = / {
return 301 http://$host/wiki/Main_Page;
}
The answer you used is a redirect, making you skip the /
location to a /wiki
location, You can try this instead
location = / {
rewrite ^ /w/index.php?title=Main_Page&$args last;
}
This should server the Main_Page for the /
URI