Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Set web server handle 404 errors for some file types using .htaccess

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #160614
    Mike Swan
    Participant

    It’s my first question in this great community (please tell me if I’m doing anything wrong). I have very specific question, which I couldn’t find on the Internet (is this possible?)…

    The goal is to set custom ErrorDocument 404, that handles not existing chosen static files like: /notfound.jpg and in a subdirectory (for any directory): /dir/notfound.jpg, for sites running under WordPress with pretty permalinks enabled. It will avoid high load on the server when some chosen static files are missing or linked incorrectly!

    I’m using a slightly modified code from the W3 Total cache plugin in my .htaccess file:

    ErrorDocument 404 /_code_404.html
    
    # BEGIN (modified) W3TC Skip 404 error handling by WordPress for static files
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !(robots\.txt|sitemap\.xml(\.gz)?)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} \.(css|js|bmp|gif|ico|jpg|jpeg|jpe|png|swf)$ [NC]
    RewriteRule .* - [L]
    </IfModule>
    # END (modified) W3TC Skip 404 error handling by WordPress for static files
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    

    I’m trying it on 2 different servers with Cpanel, on shared plans, both have WordPress with pretty permalinks and the result is the same:

        Works just as expected for requests like http://mydomain.com/notfound.jpg
    
        Doesn't work for not found file in a subdirectory like this http://mydomain.com/dir/notfound.jpg. In this case the WP handles the request and shows 404 page, which I want to avoid for certain file types, i.e. for static files like: css, js, jpg and a few more...
    

    Any answers and comments are welcome, thanks! I can try any suggestions you may have (even untested).

    #161053
    sudhakar1
    Participant

    Hi,

    There is some URL is broken and then you select backend nd select a global configuration and there is change to rewrite URL mode is “yes”

    #161055
    Mike Swan
    Participant

    Well i will look into the matter and hope so get it resolved.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.