• Here are the default multisite rules for Apache.

    
    RewriteRule ^index\.php$ - [L]
    
    RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    

    If I pass to the server https://wordpress-site.com/dummy.php, I get back a page saying

    
    File not found.
    

    But if I pass to the server https://wordpress-site.com/dummy/dummy.php, I get back a page saying

    Internal Server Error
    

    which according to the logs is the result of too many internal redirects.

    If I change RewriteRule ^(.*\.php)$ $1 [L] to RewriteRule ^(.*\.php)$ – [L], then the Internal Server Error gets replaced by Apache’s “Not Found” page.

    1) Where does the “File Not Found” page come from? I can’t find this string in this context anywhere in the WordPress installation.

    2) Why does RewriteRule ^(.*\.php)$ $1 [L] give too many redirects whereas the RewriteRule ^(.*\.php)$ – [L] not do that?

    3) Why is the behavior different at all between the two different URLs?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Those are from Apache itself… If you had a 404 error page available for the server then you probably would have seen the 404 page…

    The two many redirects are basically Apache trying to recursively look in a NON-EXISTENT directory then giving up and not finding the 404 page either.

    You can add 404 pages to Apache itself and you can change or add to your htaccess file but I’d leave htaccess alone unless I had good reason to change it.

    Once Apache decides to hand off the URL to WordPress then WordPress will handle the 404 errors.

    Sometimes you’ll find someone or something causing errors that you know WordPress might handle well or you need some custom handler or error page for that…

    In those cases you might try creating those custom htaccess directives here…

    https://www.rapidtables.com/web/tools/redirect-generator.html

    There’s also this for custom pages from WPMUDev…

    https://premium.wpmudev.org/blog/customize-error-pages-wordpress/

    And this from WPBeginner…

    https://www.wpbeginner.com/wp-themes/how-to-improve-your-404-page-template-in-wordpress/

    I lean on the 301 Generator a lot as it renders code fast that works properly. You may not need it but do look at it if you have time. It’s right interesting.

    Hope this helps.

    Thread Starter mauricev2

    (@mauricev2)

    Those are from Apache itself… If you had a 404 error page available for the server then you probably would have seen the 404 page…

    I tried this and that’s not what happens. https://wordpress-site.com/dummy.php still returns “File not found” and not the 404 page. That would suggest it’s not coming from apache, no?

    The two many redirects are basically Apache trying to recursively look in a NON-EXISTENT directory then giving up and not finding the 404 page either.

    Adding the 404 page made no difference here either. It’s still not clear to me how RewriteRule ^(.*\.php)$ $1 [L] differs from RewriteRule ^(.*\.php)$ – [L], which does show the 404 page.

    Thread Starter mauricev2

    (@mauricev2)

    File not found appears to be coming from php-fpm. By adding “ProxyErrorOverride On” to the FilesMatch section like so

    
    <FilesMatch \.php$>
            SetHandler "proxy:fcgi://127.0.0.1:9000"
            ProxyErrorOverride On
    </FilesMatch>
    

    I am able to get the 404 document.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘odd behavior with default rewrite rules’ is closed to new replies.