2

So I'm fairly new at this and I have a nginx server up and running to a simple web-page. The configuration that I have on sites-available is:

server {
    listen 80 default_server;

    root /var/www/mywebsite/;
    index /html/index.html;

    server_name mywebsite.com www.mywebsite.com;

    location / {
            try_files $uri $uri/ =404;
    }
}

And my index.html is located at this structure:

+------+   +----------+    
+ html +-->+index.html|    
+------+   +----------+    
       |      
       |   +--------------+
       +-->+scnd_page.html|
           +--------------+

When I access mywebsite.com, I see index.html. How could I make mywebsite.com/scnd_page/ to point to send_page.html?

I've tried some stuff creating

location /scnd_page { 
}

But I'm not sure if I'm on the right track. Is this even to be done on this file?

2

2 Answers 2

0

You could use rewrite to make sure to issue external redirects, such that the .html would never be visible to the user, and try_files to serve the actual files.

location / {
    rewrite     ^(/.*)\.html$   $1  redirect;
    try_files $uri $uri/index.html $uri.html =404;
}

I wouldn't recommend supporting a trailing slash /$ to imply \.html$, though; the logic for such support would be a bit ugly, plus it'll also cause extra issues if you try to use relative URLs within said scnd_page.html.

0

You can just configure the index parameter inside the location block:

location /html/scnd_page { index scnd_page.html; }

Also you can just define as "secondary" index the scnd_page.html globally:

server {

listen 80 default_server;

root /var/www/mywebsite/;
# carefull setting '/html/index.html'...
index index.html scnd_page.html;

server_name mywebsite.com www.mywebsite.com;

location / {
        try_files $uri $uri/ =404;
}

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .