3

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

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
vapouryh
  • 41
  • 6

2 Answers2

3

If you don't want to change the URL then simply remove the redirect flag from your RewriteRule .

Do the following :

Change

RewriteRule ^(.*)$ /HTML/pages/construction.html [R=302,L]

To

RewriteRule ^(.*)$ /HTML/pages/construction.html [L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
1

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 the R flag.

For example:

Options +FollowSymlinks

ErrorDocument 404 /HTML/error-pages/404.html
ErrorDocument 503 /HTML/pages/construction.html

RewriteEngine On

# 503 Service Unavailable except for the given IP address
RewriteCond %{REMOTE_ADDR} !^203\.0\.113\.111$
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule !\.(jpe?g?|png|gif|css|ico|mp4)$ - [NC,R=503,L]

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:

  1. 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.

  2. 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.

MrWhite
  • 43,179
  • 8
  • 60
  • 84