Problem redirecting 403 Forbidden to 404 Not Found

后端 未结 8 1368
心在旅途
心在旅途 2020-12-05 08:58

The pertinent part of my .htaccess looks like this:

Options -Indexes

    Order allow,deny
    Deny from all

Re         


        
相关标签:
8条回答
  • 2020-12-05 09:47

    In that case you do not need to use Options -Indexes My solution to stop displaying directory's content as list and display 404 error is simple. Create .htaccess file in root directory of your project and write which directories should be protected.

    Directories structure

    - your_root_directory
      - .htaccess
      - 404.html
      - index.html 
      - app
        - other files I do not want to show
      - models
        - other files I do not want to show
    

    .htaccess

    RewriteEngine On
    RewriteRule   ^app/ - [R=404,L]
    RewriteRule   ^models/ - [R=404,L]
    

    ErrorDocument 404 /your_root_directory/404.html The second line of .htaccess disallow access to list items in app directory and all its subridectories.

    The third line of .htaccess disallow access to list items in models directory and all its subridectories.

    The fourth of .htaccess line sets our own 404 error (if you do not want to show apache default error).

    Remember to clear cache on your browser when you work with htaccess.

    0 讨论(0)
  • 2020-12-05 09:49

    Another possibility is not to bother matching the whole path:

    RedirectMatch 404 ^/include
    

    If there are publicly visible URL paths that might start with "/include" (say, "/includeMe"), a small addition will separate the private from the public URLs:

    RedirectMatch 404 ^/include(/|$)
    
    0 讨论(0)
提交回复
热议问题