6

root directory = /srv/myproject/xyz/main/

in the "main" folder I have few *.html files and I want all of them to point at a url say /test/ (which is quite different from the directory structure)

this is my very basic nginx configuration

server {
    listen                80;
    error_log   /var/log/testc.error.log;

    location /test/ {
         root   /srv/myproject/xyz/main/;
         #alias /srv/myproject/xyz/main/;
         default_type   "text/html";
         try_files  $uri.html ;
    }
}

If I use simple alias

location /test/ {
       alias /srv/myproject/xyz/main/;   
}

then its work perfectly, I mean I can access those html files by http://www.myurl.com/test/firstfile.html and so on

but I dont want that html extension.

I tried to follow these threads but no success http://forum.nginx.org/read.php?11,201491,201494

How to remove both .php and .html extensions from url using NGINX?

how to serve html files in nginx without showing the extension in this alias setup

1 Answer 1

6

Try this

location ~ ^/test/(.*)$ {
    alias /srv/myproject/xyz/main/;
    try_files $1.html =404;
}
Sign up to request clarification or add additional context in comments.

1 Comment

What about URLs with trailing slash?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.