Reputation: 6541
I tried the other solutions on overflow, but those solutions do not work for me. There is not much documentation with any answers so it is harder to apply outside their specific case.
I already have site.com redirecting to www.site.com with
server {
listen 10.10.10.10;
server_name site.com;
rewrite / $scheme://www.$host$request_uri permanent;
}
And I want to add a site.com/index redirect to site.com. Anything I get to work becomes a loop.
EDIT
Based on defenestrate.me's answer and other info I picked up -
The usual config -
location / {
index index.html index.php;
}
Sends root to index.html etc. So if index.html is redirecting to root this will redirect back to index so an if function is needed as in the answer.
Upvotes: 0
Views: 1137
Reputation: 126
I've just managed to get this working by using the following inside just a server section:
if ($request_uri = /index.php) {
return 301 $scheme://$host;
}
I'm not overly proficient in nginx but I'll try to answer your questions (someone please correct me if I'm wrong)
You'd probably have to add it to both the post 80 and port 443 sections for it to work, I don't think adding it to a site-wide listener would work.
You need to keep the index index.html index.php; line as it specifies which default files to load if one isn't specified (navigating to a folder for example)
Upvotes: 3