htaccess 302 Redirect all the request to a domain to html file

Redirecting all the requests coming to the domain to the index.html file or some html file using htaccess file.
This redirection is used when the domain is offline and want to show some html page which contains the message to the users who visits the site.

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$ # if not index.html file
RewriteRule .* /index.html [L,R=302] # redirects/rewrite to some html file ( index.html)

To exclude specific folder

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/images/ # folder to be excluded
RewriteCond %{REQUEST_URI} !^/index.html$ # if not index.html file
RewriteRule .* /index.html [L,R=302] # redirects/rewrite to some html file ( index.html)

Leave a Reply

Your email address will not be published. Required fields are marked *