14

This should be really easy to do but I'm hitting my head on the wall. If I get a request for www.mysite.com/mypath I want to serve the content of www.mysite.com/myotherpath/thisfile.html. How can I do this with an nginx config.

Michael Gorham
  • 1,234
  • 2
  • 16
  • 24

2 Answers2

15
location = /mypath {
    try_files /myotherpath/thisfile.html =404;
}
VBart
  • 14,714
  • 4
  • 45
  • 49
9

Use rewrite directive within proper location block. So for example you have basic location which will handle all requests

location / {
    /*your rules here*/
}

You will need to add another block, which will do for you handling of specific path

location /mypath {
    rewrite ^/mypath$ /real/path/to/file/thisfile.html; 
}

Also for your server to think in that block that thisfile.html is default you can use try thisfile.html directive

It is all well explained on official page Official Nginx RewriteModule page

VBart
  • 14,714
  • 4
  • 45
  • 49
Alexey Kamenskiy
  • 2,888
  • 5
  • 36
  • 56