0

Currently I use this code in my .htaccess file to trigger my Site's maintenance page.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
Header Set Cache-Control "max-age=0, no-store"
</IfModule>

How Would I make it so I could still access a directory I would be working On and not just my IP address in case my friend wishes to access it.

I have done some searching, but not found anything as of yet

Cheers

Tom

Tom Roman
  • 13
  • 5
  • Ok, sounds like a good plan. Go for it! (_or did you have any question here?_) – arkascha Jan 02 '17 at 11:01
  • @arkascha Yes I did, if you read I said i wanted to make it so I could access it while the maintenance page is up – Tom Roman Jan 02 '17 at 11:03
  • You did write that. But that is 1. not a question but a statement and 2. that is nothing suited as a question here. For that you need to show your own attempt to solve the task, not just to ask: "do that for me". You see we are not a free coding service. You are expected to be able to use your tools yourself. Only if you get stuck _with your own attempt_, then is the time to ask a specific question here. If you are not able to or simply to lazy to start yourself, then I suggest you hire a payed programmer to do your work for you. – arkascha Jan 02 '17 at 11:05
  • @arkascha I appreciate the comment and will modify the way the question is written, but I have looked for a solution and not found anything. – Tom Roman Jan 02 '17 at 11:06
  • The please add your own attempt and point out what _exactly_ is not working with it. – arkascha Jan 02 '17 at 11:07

1 Answers1

0

I'd say you can simply implement some exception rules prior to your handling of the maintenance mode:

<IfModule mod_rewrite.c>
RewriteEngine On

# immediately end all rewriting for specific IPV4 addresses
RewriteCond %{REMOTE_ADDR} ^123\.123\.123\.123$ [OR]
RewriteCond %{REMOTE_ADDR} ^321\.321\.321\.321$
RewriteRule ^ - [END]

# for everyone else: check for maintenance mode
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
Header Set Cache-Control "max-age=0, no-store"
</IfModule>

Alternatively you could add the negated conditions as additional conditions to the maintenance mode rewriting logic. But I think the above is easier to read and maintain.

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • Unfortunately for some reason, it goes to internal error 500 when using the code you have given me – Tom Roman Jan 02 '17 at 11:31
  • And what is the exact error message you get in your http servers error log file? – arkascha Jan 02 '17 at 11:33
  • After looking, there are no recent errors in the log file – Tom Roman Jan 02 '17 at 11:45
  • An http status 500 definitely creates an entry in the error log file, unless you explicitly disabled logging. – arkascha Jan 02 '17 at 11:46
  • Ah, it could be that you are using a really old version of the apache http server that does not know the `[END]` flag. In that case just replace it with a `[L]`. – arkascha Jan 02 '17 at 11:48
  • Ah there we go, that got rid of the Server Error, thank you. However, It is still showing the page for my IP even though I filled it into the 'Whitelist' Essentially – Tom Roman Jan 02 '17 at 11:57
  • Then either that request comes with another IP address, keep in mind different network topologies, internet addresses, proxies, NAT, ... so check your http servers access log file and compare. Or you simply see a cached result, so clear your browsers cache or do a "deep reload". – arkascha Jan 02 '17 at 12:43