Home  >  Q&A  >  body text

How to set nginx to make a directory inaccessible

I wrote a url rewrite, structure:

http://xxx.com/abc -> index.php/abc
http://xxx.com/abc/bcd -> index.php/abc/bcd

The abc/ directory must exist in the root directory for special reasons. At this time, something goes wrong. When accessing http://xxx.com/abc, you directly access this directory instead of url rewrite, but I hope it is the other way around. Prioritize access to rewrite, not the directory. At the same time, there is also a requirement that this is only true for this directory. Other directories should still access the directory first, and then rewrite

rewrite I wrote like this:

if (!-e $request_filename){
    rewrite ^/(.*)$ /index.php?/;
}
世界只因有你世界只因有你2712 days ago906

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:30:57

    location /xxx {
     deny all;
     return 403;
    }
    

    xxx is the directory name

    reply
    0
  • Cancelreply