mod_rewrite based on ip





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







13















I'd like to implement mod_rewrite to put my site into maintenance. Basically all IP addresses except a handful we specify would be forwarded to a static html page.



Please can someone help with this rule. Also is there a way to turn this on and off easily without editing the htaccess file?










share|improve this question

























  • You may also want to serve your maintenance page with a 503 HTTP status code

    – Hagen von Eitzen
    Aug 12 '18 at 20:01


















13















I'd like to implement mod_rewrite to put my site into maintenance. Basically all IP addresses except a handful we specify would be forwarded to a static html page.



Please can someone help with this rule. Also is there a way to turn this on and off easily without editing the htaccess file?










share|improve this question

























  • You may also want to serve your maintenance page with a 503 HTTP status code

    – Hagen von Eitzen
    Aug 12 '18 at 20:01














13












13








13


3






I'd like to implement mod_rewrite to put my site into maintenance. Basically all IP addresses except a handful we specify would be forwarded to a static html page.



Please can someone help with this rule. Also is there a way to turn this on and off easily without editing the htaccess file?










share|improve this question
















I'd like to implement mod_rewrite to put my site into maintenance. Basically all IP addresses except a handful we specify would be forwarded to a static html page.



Please can someone help with this rule. Also is there a way to turn this on and off easily without editing the htaccess file?







apache .htaccess mod-rewrite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 24 '17 at 23:12









rink.attendant.6

17.8k1867112




17.8k1867112










asked Jul 2 '09 at 11:32









JoshJosh

5,27212853




5,27212853













  • You may also want to serve your maintenance page with a 503 HTTP status code

    – Hagen von Eitzen
    Aug 12 '18 at 20:01



















  • You may also want to serve your maintenance page with a 503 HTTP status code

    – Hagen von Eitzen
    Aug 12 '18 at 20:01

















You may also want to serve your maintenance page with a 503 HTTP status code

– Hagen von Eitzen
Aug 12 '18 at 20:01





You may also want to serve your maintenance page with a 503 HTTP status code

– Hagen von Eitzen
Aug 12 '18 at 20:01












3 Answers
3






active

oldest

votes


















18














You can use the REMOTE_ADDR variable in a RewriteCond



RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
RewriteRule ^ /maintenance.html


Just change the condition to match the IPs you want, for more than one you can use ^(ip1|ip2|...|ipn)$.



About how to disable the maintenance mode without changing the .htaccess file I think that's not possible short of writing a program that would delete it or otherwise modify it, an easy one would be to rename it.






share|improve this answer


























  • Don’t forget to mark the start and end in your regular expression.

    – Gumbo
    Jul 2 '09 at 11:42



















1














I'd like to slightly correct Vinko Vrsalovic's answer.



RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
RewriteRule ^ /maintenance.html


This rule result will be infinite loop and HTTP server error, because it will be executed on redirection page too. To make it work you should exclude redirection page from the rule. It can be done this way:



RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteRule .* /maintenance.html [R=302,L]





share|improve this answer

































    0














    you could enable this state and disable it via some admin interface that is able to write to .htaccess (e.g. permissions set to 755 or 777). it would just always find the .htaccess, insert those two lines at the beginning and on disabling maintenance it would delete those two lines, leaving the rest of the file untouched






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1073852%2fmod-rewrite-based-on-ip%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      18














      You can use the REMOTE_ADDR variable in a RewriteCond



      RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
      RewriteRule ^ /maintenance.html


      Just change the condition to match the IPs you want, for more than one you can use ^(ip1|ip2|...|ipn)$.



      About how to disable the maintenance mode without changing the .htaccess file I think that's not possible short of writing a program that would delete it or otherwise modify it, an easy one would be to rename it.






      share|improve this answer


























      • Don’t forget to mark the start and end in your regular expression.

        – Gumbo
        Jul 2 '09 at 11:42
















      18














      You can use the REMOTE_ADDR variable in a RewriteCond



      RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
      RewriteRule ^ /maintenance.html


      Just change the condition to match the IPs you want, for more than one you can use ^(ip1|ip2|...|ipn)$.



      About how to disable the maintenance mode without changing the .htaccess file I think that's not possible short of writing a program that would delete it or otherwise modify it, an easy one would be to rename it.






      share|improve this answer


























      • Don’t forget to mark the start and end in your regular expression.

        – Gumbo
        Jul 2 '09 at 11:42














      18












      18








      18







      You can use the REMOTE_ADDR variable in a RewriteCond



      RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
      RewriteRule ^ /maintenance.html


      Just change the condition to match the IPs you want, for more than one you can use ^(ip1|ip2|...|ipn)$.



      About how to disable the maintenance mode without changing the .htaccess file I think that's not possible short of writing a program that would delete it or otherwise modify it, an easy one would be to rename it.






      share|improve this answer















      You can use the REMOTE_ADDR variable in a RewriteCond



      RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
      RewriteRule ^ /maintenance.html


      Just change the condition to match the IPs you want, for more than one you can use ^(ip1|ip2|...|ipn)$.



      About how to disable the maintenance mode without changing the .htaccess file I think that's not possible short of writing a program that would delete it or otherwise modify it, an easy one would be to rename it.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jul 2 '09 at 12:31

























      answered Jul 2 '09 at 11:38









      Vinko VrsalovicVinko Vrsalovic

      207k43300350




      207k43300350













      • Don’t forget to mark the start and end in your regular expression.

        – Gumbo
        Jul 2 '09 at 11:42



















      • Don’t forget to mark the start and end in your regular expression.

        – Gumbo
        Jul 2 '09 at 11:42

















      Don’t forget to mark the start and end in your regular expression.

      – Gumbo
      Jul 2 '09 at 11:42





      Don’t forget to mark the start and end in your regular expression.

      – Gumbo
      Jul 2 '09 at 11:42













      1














      I'd like to slightly correct Vinko Vrsalovic's answer.



      RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
      RewriteRule ^ /maintenance.html


      This rule result will be infinite loop and HTTP server error, because it will be executed on redirection page too. To make it work you should exclude redirection page from the rule. It can be done this way:



      RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
      RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
      RewriteRule .* /maintenance.html [R=302,L]





      share|improve this answer






























        1














        I'd like to slightly correct Vinko Vrsalovic's answer.



        RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
        RewriteRule ^ /maintenance.html


        This rule result will be infinite loop and HTTP server error, because it will be executed on redirection page too. To make it work you should exclude redirection page from the rule. It can be done this way:



        RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
        RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
        RewriteRule .* /maintenance.html [R=302,L]





        share|improve this answer




























          1












          1








          1







          I'd like to slightly correct Vinko Vrsalovic's answer.



          RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
          RewriteRule ^ /maintenance.html


          This rule result will be infinite loop and HTTP server error, because it will be executed on redirection page too. To make it work you should exclude redirection page from the rule. It can be done this way:



          RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
          RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
          RewriteRule .* /maintenance.html [R=302,L]





          share|improve this answer















          I'd like to slightly correct Vinko Vrsalovic's answer.



          RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
          RewriteRule ^ /maintenance.html


          This rule result will be infinite loop and HTTP server error, because it will be executed on redirection page too. To make it work you should exclude redirection page from the rule. It can be done this way:



          RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
          RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
          RewriteRule .* /maintenance.html [R=302,L]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 19 '18 at 15:49

























          answered Nov 24 '18 at 14:38









          Alexander MikhailovAlexander Mikhailov

          114




          114























              0














              you could enable this state and disable it via some admin interface that is able to write to .htaccess (e.g. permissions set to 755 or 777). it would just always find the .htaccess, insert those two lines at the beginning and on disabling maintenance it would delete those two lines, leaving the rest of the file untouched






              share|improve this answer




























                0














                you could enable this state and disable it via some admin interface that is able to write to .htaccess (e.g. permissions set to 755 or 777). it would just always find the .htaccess, insert those two lines at the beginning and on disabling maintenance it would delete those two lines, leaving the rest of the file untouched






                share|improve this answer


























                  0












                  0








                  0







                  you could enable this state and disable it via some admin interface that is able to write to .htaccess (e.g. permissions set to 755 or 777). it would just always find the .htaccess, insert those two lines at the beginning and on disabling maintenance it would delete those two lines, leaving the rest of the file untouched






                  share|improve this answer













                  you could enable this state and disable it via some admin interface that is able to write to .htaccess (e.g. permissions set to 755 or 777). it would just always find the .htaccess, insert those two lines at the beginning and on disabling maintenance it would delete those two lines, leaving the rest of the file untouched







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 2 '09 at 11:43









                  dusoftdusoft

                  8,50253139




                  8,50253139






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1073852%2fmod-rewrite-based-on-ip%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini