• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Set web server handle 404 errors for some file types using .htaccess

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Set web server handle 404 errors for some file types using .htaccess

This topic is: not resolved

Tagged: 404, Wordpress

  • This topic has 1 reply, 2 voices, and was last updated 9 years, 5 months ago by Susan.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • January 17, 2014 at 3:24 am #85597
    Markupcloud
    Member

    I had learned a lot from answers here and now 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).


    PSD to WordPress Theme Conversion

    April 1, 2014 at 9:38 am #97898
    Susan
    Moderator

    As you posted this more than 2 months ago, I hope you were able to get your issue resolved. If not, please report back here, and I will escalate for you.

    If it has been resolved, please update the thread, and I will close it.

    Thanks!

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble