[wp-trac] [WordPress Trac] #20746: Accessing non-existing theme folder in Network install gives 500 error

WordPress Trac noreply at wordpress.org
Wed Aug 30 15:49:37 UTC 2023


#20746: Accessing non-existing theme folder in Network install gives 500 error
-------------------------------------------------+-------------------------
 Reporter:  arkimedia                            |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Rewrite Rules                        |     Version:  3.3.2
 Severity:  normal                               |  Resolution:
 Keywords:  needs-testing has-patch dev-         |     Focuses:  multisite
  feedback 2nd-opinion                           |
-------------------------------------------------+-------------------------

Comment (by germanoronoz):

 Hello Everyone,

 I've come up with a workaround.

 Before this rewrites:


 {{{
 RewriteRule ^(wp-(content|admin|includes).*) - [L]
 RewriteRule ^(.*\.php)$ - [L]
 }}}

 I am adding a redirect for those non-existent URLs inside wp-content|wp-
 admin|wp-includes:

 {{{
 RewriteCond %{REQUEST_URI} (wp-content|wp-admin|wp-includes) [NC]
 RewriteCond %{REQUEST_URI} !error-404 [NC]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^ https://%{HTTP_HOST}/error-404/%{REQUEST_URI} [R=301,L]
 }}}

 So before passing those urls to Apache and thus before throwing Apache's
 404 error, they are being redirected, from (for example):

 {{{
 https://www.domain.com/wp-content/uploads/sites/666/2023/08/non-existent-
 image.jpg
 }}}

 To:

 {{{
 https://www.domain.com/error-404/wp-content/uploads/sites/666/2023/08/non-
 existent-image.jpg
 }}}

 So now this leads to a 404 error, **but managed inside WP instead of
 Apache.**

 Then we can use redirection plugins (such as Redirection or Rank Math) to
 create redirects even with regex, for example from:

 {{{
 ^error-404/wp-content/uploads/(.*)
 }}}

 To:

 {{{
 https://www.newdomain.com/wp-content/uploads/sites/888/$1
 }}}


 **Not optimal but at least is a working workaround.**

 Regards!

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/20746#comment:63>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list