Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. $ip = $_SERVER['REMOTE_ADDR'];
  2.  
  3. $allowed = array('1.1.1.1','2.2.2.2'); // these are the IP's that are allowed to view the site.
  4.  
  5. if (file_exists($maintenanceFile)) {
  6.  
  7. if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {
  8.  
  9. // account for load balancer that passes client IP
  10. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  11. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  12. }
  13. if(empty($ip)) {
  14. $ip = $_SERVER['REMOTE_ADDR'];
  15. }
  16.  
  17. // whitelist your ips
  18. $allowed = array();
  19. $allowed[]='WHITELIST.IP.ADDRESS.#1';
  20. $allowed[]='WHITELIST.IP.ADDRESS.#2';
  21.  
  22. if (file_exists($maintenanceFile)) {
  23. if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {
  24. include_once dirname(__FILE__) . '/errors/503.php';
  25. exit;
  26. }
  27. }
  28.  
  29. if (file_exists($maintenanceFile)) {
  30. include_once dirname(__FILE__) . '/errors/503.php';
  31. exit;
  32. }
  33.  
  34. if (file_exists($maintenanceFile) && strpos($_SERVER['REQUEST_URI'], '/admin/') === false) {
  35. include_once dirname(__FILE__) . '/errors/503.php';
  36. exit;
  37. }
  38.  
  39. RewriteEngine On
  40. ErrorDocument 503 /errors/503.php
  41. RewriteCond %{REMOTE_ADDR} !^4.3.2.1 [NC] #your IP
  42. RewriteCond %{REMOTE_ADDR} !^4.3.2.2 [NC] #other IP if needed
  43. RewriteCond %{REMOTE_ADDR} !^127.0.0.1 [NC] #localhost maybe needed depending on server setup
  44. RewriteCond %{REQUEST_URI} !^/errors/503.php
  45. RewriteCond %{REQUEST_URI} !^/media/
  46. RewriteCond %{REQUEST_URI} !^/images/
  47. RewriteCond %{REQUEST_URI} !^/css/
  48. RewriteCond %{REQUEST_URI} !^/js/
  49. RewriteCond %{REQUEST_URI} !^/skin/
  50. RewriteCond %{REQUEST_URI} !^/index.php
  51. RewriteCond %{REQUEST_URI} !^/admin #your admin path
  52. RewriteCond %{REQUEST_URI} !^/admin/
  53. RewriteRule ^(.*) http://www.yourwebsite.com/errors/503.php [L,R=503]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement