Problem redirecting 403 Forbidden to 404 Not Found

后端 未结 8 1371
心在旅途
心在旅途 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:35

    With rewrite mod:

    RewriteEngine on
    
    RewriteCond %{THE_REQUEST} ^.*/\.
    RewriteRule ^(.*)$ - [R=404]
    

    Every file or dir who begin with a dot will be redirected to 404.

    /myDir/.svn => 404
    /.gitignore => 404
    /dir1/dir2_dir3/
    

    Or to change all 403,400 errors into 404 errors, put this at the end of /etc/apache2/conf.d/localized-error-pages OR into a .htaccess

    # Will raise a 404 error, because the file  doesn't exist.
    # We change 403 or 400 to 404 !
    ErrorDocument 400 /fake_file_for_apache_404.php
    ErrorDocument 403 /fake_file_for_apache_404.php
    # We need to rewrite 404 error, else we will have "fake_file_for_apache_404.php not found"
    ErrorDocument 404 "404 Not Found

    Not Found

    The requested URL was not found on this server.

    " ErrorDocument 500 "Server in update. Please comme back later."

提交回复
热议问题