skip to Main Content

I’ve seen several answers to this, but none of them seem to work on subdirectories or nested URLs.

Basically, I want to redirect everything on a domain, no matter whether specified with a direct URL or a directory, no matter how deeply nested, to a “site closed” or “maintenance” page, on the same domain.

For example, all of these:

example.com
example.com/page.html
example.com/sub
example.com/sub/page.html
example.com/sub/sub2
example.com/sub/sub2/page.html

…should redirect to https://example.com/index_closed.html

I can get it to work on example.com, but not nested directories.

Also, it should NOT redirect .css files, if possible. Thanks!

2

Answers


  1. Chosen as BEST ANSWER

    I found that the following works:

    RewriteCond %{REQUEST_URI} !/index_closed.html$ 
    RewriteCond %{REQUEST_URI} !.css$ [NC]
    RewriteCond %{REQUEST_URI} !.jpg$ [NC]
    RewriteRule $ /index_closed.html [R=302,L]
    

  2. RewriteBase /

    RewriteRule ^$ https://example.com/index_closed.html [R=301,L]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search