503 htaccess file only partially working

Using the following as a 503 forwarder on a wordpress website. For some reason it words for foo.com/xyz, but not foo.com itself. Any thoughts?

.htaccess file:

ErrorDocument 503 /rdi/index.php

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /rdi/index.php [R=503,L]

Related posts

Leave a Reply

1 comment

  1. Any url that ends with a / requests a folder, and any url that does not end on a / requests a file. When you request http://example.com, you actually request http://example.com/, the document root of example.com. Your document root is obviously an existing folder, since otherwise you wouldn’t be able to run a site at all.

    You are using the following rule:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* /rdi/index.php [R=503,L]
    

    The second condition says: “If the requested filename is not a directory”. Your document root is a directory, so that condition is false. It won’t rewrite.

    You can use the following rule:

    RewriteCond %{REQUEST_URI} ^/$ [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* /rdi/index.php [R=503,L]
    

    What will this do? If you request http://example.com, the first condition will match, the second will be ignored because of the [OR] flag, and the third condition will be true. If you request http://example.com/rdi/, the first condition will be false and the second condition will be false and so the rule will not be used. If you request http://example.com/asdfasdf/, the first condition will be false, but due to the [OR] flag it will try the second condition, which is true. Then it checks the third condition which is true, which will then rewrite the request.