URI re-mapping using try_files

mrtn nginx-forum at nginx.us
Thu Oct 11 19:59:24 UTC 2012

Hi Francis,

Thanks for introducing me to rewrite directive. Just to confirm, this is how
I should use your rewrite:

root     /home/www/example;

location /public/doc/ {
    rewrite           (.*)/(.*) $1/$2/$2.html break;

Ideally, for the other cases you raised, I want the following to happen:


when the query string (e.g. ?para=blah) part is missing or incomplete, I
want to serve a generic error page (e.g. /error.html)


when the user tries to access the actual html page directly, I want to block
it by either returning a 404 or serving a generic error page as above


when the user queries an URI that has no corresponding .html file on the
server, I want to simply return a 404.

Can all these be implemented using rewrite only? Thanks.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,231672,231682#msg-231682

More information about the nginx mailing list