I have a .htaccess file and i’ve set up a ‘Coming Soon’ website. It excludes my ip as i’m the developer but for other visitors I don’t wan’t it to change the url of the address.
Here’s the file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^12.345.67.89$
RewriteCond %{REQUEST_URI} !/HTML/pages/construction.html
RewriteCond %{REQUEST_URI} !.(jpe?g?|png|gif|css|ico|mp4) [NC]
RewriteRule ^(.*)$ /HTML/pages/construction.html [R=302,L]
ErrorDocument 404 /HTML/error-pages/404.html
How can I do this? Help is very much appreciated
2
Answers
If you don’t want to change the URL then simply remove the redirect flag from your
RewriteRule
.Do the following :
Change
To
There is no "503" response in the code presented here unless you are manually setting the HTTP response status in your server-side script. But if this is a
.html
file then that seems unlikely.To correctly serve a "503 Service Unavailable" response you should define the appropriate
ErrorDocument
and call this using theR
flag.For example:
Despite the use of the
R
flag, there is no external redirect here. (A redirect only occurs for status codes in the 3xx range.)The condition that checks against the
REDIRECT_STATUS
environment variable does two things:It ensures that an internal subrequest for the 503 ErrorDocument itself doesn’t trigger a 503 – which would result in an endless loop and no custom ErrorDocument is returned in the response.
A direct request for the
/HTML/pages/construction.html
document (the 503 ErrorDocument) will itself trigger a 503 response.Also note that if you are sending a 503 response, you should ideally be sending a
Revisit-After
HTTP response header as well to indicate to (search engine) bots when your site will be available.