.htaccess redirect to file within directory

Viewed 138

Website will be going down for maintenance very soon. In the mean while all visitors will be redirected to a page indicating that the website will be down for a short period of time until maintenance is complete.

If I wanted to redirect all traffic that doesn't match my IP to this page located within the maintenance directory

https://example.com/maintenance/index.php

Would these rewrite rules be valid and/or work for what I'm trying to accomplish?

RewriteCond %{REQUEST_URI} !/maintenance/index.php$ 
RewriteCond %{REMOTE_ADDR} !^192\.192\.192\.192$
RewriteRule $ /maintenance/index.php [R=302,L]
1 Answers

Do this in .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /maintenance/index.php [L,QSA]

Anyone visits some link on your website will be redirected to:

www.yourwebsite.extension/maintenance/index.php

Related