• I’m trying to setup a sitewide 503 response with a custom 503 error page all within htaccess on the root of a WordPress site. This works absolutely fine but I now need to exclude any POST/GET requests to /wp-json/ which I know translates to index.php/?rest_route

    Feeling like I have tried every RewriteCond possible to exclude this but its not working. Has anyone else done this or can help point me in the right direction? I’ve been testing on a blank WP install so I know its not being affected by any customisation.

    Few I’ve tried

    RewriteEngine On

    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|ico) [NC]

    RewriteCond %{REQUEST_URI} !^/wp-json/ [NC]
    RewriteCond %{REQUEST_URI} !^/wp-json [NC]
    RewriteCond %{REQUEST_URI} !^.*wp-json/ [NC]
    RewriteCond %{REQUEST_URI} !^/wp-json.* [NC]
    RewriteCond %{ENV:REDIRECT_STATUS} !=503
    RewriteRule .* /maintenance.html [R=503,L]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi. I’m not sure myself about this right now but I just wanted to point you in a direction in the meantime.

    It would help someone if you could post the full .htaccess file contents. Are you getting any errors from Apache?

    I’d also recommend posting on the Apache user support and discussion mailing list:
    http://httpd.apache.org/lists.html#http-users

    I’ve got an issue myself that I need to post up so I really appreciate you posting here which has reminded me to do so.

    Hi @notmattadamson! From your description, it seems like it’s possible that you may also need to exclude index.php/?rest_route URIs from the maintenance condition. Can you try adding the following to your .htaccess file and see if this works?

    
    RewriteEngine On
    
    # Pass any request that matches index.php?rest_route
    RewriteCond %{REQUEST_URI} ^index\.php$ [NC]
    RewriteCond %{QUERY_STRING} ^rest_route.* [NC]
    RewriteRule .* - [L]
    
    # Send all non-static and non-rest requests to maintenance page
    RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|ico) [NC]
    RewriteCond %{REQUEST_URI} !^/wp-json/ [NC]
    RewriteCond %{REQUEST_URI} !^/wp-json [NC]
    RewriteCond %{REQUEST_URI} !^.*wp-json/ [NC]
    RewriteCond %{REQUEST_URI} !^/wp-json.* [NC]
    RewriteCond %{ENV:REDIRECT_STATUS} !=503
    RewriteRule .* /maintenance.html [R=503,L]
    

    Additionally, you might be able to use WordPress’s native wp_is_maintenance_mode instead of .htaccess redirects: wp_is_maintenance_mode

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WP-JSON / REST excluded from RewriteRule’ is closed to new replies.