RewriteCond ignored in httpd.conf

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












Put simply this works in htaccess:



RewriteEngine on

RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d

RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]


But when I move it to httpd.conf it does nothing. I have tried in the directory directive and that also makes no difference.



As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.



RewriteEngine on

RewriteCond %SCRIPT_FILENAME !-f
RewriteCond %SCRIPT_FILENAME !-d

RewriteRule ^(.*)$ https://example.net?u=$1 [L,NC,R=301]









share|improve this question







New contributor




Guesser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    3
    down vote

    favorite












    Put simply this works in htaccess:



    RewriteEngine on

    RewriteCond %SCRIPT_FILENAME !-f
    RewriteCond %SCRIPT_FILENAME !-d

    RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]


    But when I move it to httpd.conf it does nothing. I have tried in the directory directive and that also makes no difference.



    As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.



    RewriteEngine on

    RewriteCond %SCRIPT_FILENAME !-f
    RewriteCond %SCRIPT_FILENAME !-d

    RewriteRule ^(.*)$ https://example.net?u=$1 [L,NC,R=301]









    share|improve this question







    New contributor




    Guesser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      Put simply this works in htaccess:



      RewriteEngine on

      RewriteCond %SCRIPT_FILENAME !-f
      RewriteCond %SCRIPT_FILENAME !-d

      RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]


      But when I move it to httpd.conf it does nothing. I have tried in the directory directive and that also makes no difference.



      As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.



      RewriteEngine on

      RewriteCond %SCRIPT_FILENAME !-f
      RewriteCond %SCRIPT_FILENAME !-d

      RewriteRule ^(.*)$ https://example.net?u=$1 [L,NC,R=301]









      share|improve this question







      New contributor




      Guesser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      Put simply this works in htaccess:



      RewriteEngine on

      RewriteCond %SCRIPT_FILENAME !-f
      RewriteCond %SCRIPT_FILENAME !-d

      RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301]


      But when I move it to httpd.conf it does nothing. I have tried in the directory directive and that also makes no difference.



      As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.



      RewriteEngine on

      RewriteCond %SCRIPT_FILENAME !-f
      RewriteCond %SCRIPT_FILENAME !-d

      RewriteRule ^(.*)$ https://example.net?u=$1 [L,NC,R=301]






      mod-rewrite apache2






      share|improve this question







      New contributor




      Guesser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Guesser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Guesser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 4 hours ago









      Guesser

      182




      182




      New contributor




      Guesser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Guesser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Guesser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted











          RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301] 


          But when I move it to httpd.conf it does nothing.




          Because in a server context the RewriteRule pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess the URL-path is less the directory-prefix, so never starts with a slash.




          I have tried in the directory directive and that also makes no difference.




          That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess file that enabled the rewrite engine then this would have overridden the server directives in the <Directory> container, so the <Directory> directives wouldn't have done anything still.




          As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.



          RewriteEngine on

          RewriteCond %SCRIPT_FILENAME !-f
          :



          Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME (or REQUEST_FILENAME) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).



          You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME.



          So, in a server (or virtualhost) context you would need to use the following instead:



          RewriteEngine on

          RewriteCond %LA-U:REQUEST_FILENAME !-f
          RewriteCond %LA-U:REQUEST_FILENAME !-d

          RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]


          Note the slash prefix on the RewriteRule pattern.



          The NC flag is superfluous here.






          share|improve this answer


















          • 1




            Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
            – Guesser
            2 hours ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "2"
          ;
          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',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Guesser is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f937678%2frewritecond-ignored-in-httpd-conf%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted











          RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301] 


          But when I move it to httpd.conf it does nothing.




          Because in a server context the RewriteRule pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess the URL-path is less the directory-prefix, so never starts with a slash.




          I have tried in the directory directive and that also makes no difference.




          That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess file that enabled the rewrite engine then this would have overridden the server directives in the <Directory> container, so the <Directory> directives wouldn't have done anything still.




          As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.



          RewriteEngine on

          RewriteCond %SCRIPT_FILENAME !-f
          :



          Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME (or REQUEST_FILENAME) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).



          You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME.



          So, in a server (or virtualhost) context you would need to use the following instead:



          RewriteEngine on

          RewriteCond %LA-U:REQUEST_FILENAME !-f
          RewriteCond %LA-U:REQUEST_FILENAME !-d

          RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]


          Note the slash prefix on the RewriteRule pattern.



          The NC flag is superfluous here.






          share|improve this answer


















          • 1




            Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
            – Guesser
            2 hours ago














          up vote
          3
          down vote



          accepted











          RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301] 


          But when I move it to httpd.conf it does nothing.




          Because in a server context the RewriteRule pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess the URL-path is less the directory-prefix, so never starts with a slash.




          I have tried in the directory directive and that also makes no difference.




          That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess file that enabled the rewrite engine then this would have overridden the server directives in the <Directory> container, so the <Directory> directives wouldn't have done anything still.




          As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.



          RewriteEngine on

          RewriteCond %SCRIPT_FILENAME !-f
          :



          Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME (or REQUEST_FILENAME) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).



          You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME.



          So, in a server (or virtualhost) context you would need to use the following instead:



          RewriteEngine on

          RewriteCond %LA-U:REQUEST_FILENAME !-f
          RewriteCond %LA-U:REQUEST_FILENAME !-d

          RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]


          Note the slash prefix on the RewriteRule pattern.



          The NC flag is superfluous here.






          share|improve this answer


















          • 1




            Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
            – Guesser
            2 hours ago












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted







          RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301] 


          But when I move it to httpd.conf it does nothing.




          Because in a server context the RewriteRule pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess the URL-path is less the directory-prefix, so never starts with a slash.




          I have tried in the directory directive and that also makes no difference.




          That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess file that enabled the rewrite engine then this would have overridden the server directives in the <Directory> container, so the <Directory> directives wouldn't have done anything still.




          As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.



          RewriteEngine on

          RewriteCond %SCRIPT_FILENAME !-f
          :



          Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME (or REQUEST_FILENAME) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).



          You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME.



          So, in a server (or virtualhost) context you would need to use the following instead:



          RewriteEngine on

          RewriteCond %LA-U:REQUEST_FILENAME !-f
          RewriteCond %LA-U:REQUEST_FILENAME !-d

          RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]


          Note the slash prefix on the RewriteRule pattern.



          The NC flag is superfluous here.






          share|improve this answer















          RewriteRule ^([^/]+)/?$ https://example.net?u=$1 [L,NC,R=301] 


          But when I move it to httpd.conf it does nothing.




          Because in a server context the RewriteRule pattern will never match. In a server context the URL-path is root-relative, starting with a slash. In .htaccess the URL-path is less the directory-prefix, so never starts with a slash.




          I have tried in the directory directive and that also makes no difference.




          That should have worked, providing you included the correct directory path. (And restarted Apache.) However, if you still had a .htaccess file that enabled the rewrite engine then this would have overridden the server directives in the <Directory> container, so the <Directory> directives wouldn't have done anything still.




          As a test the below in httpd.conf does have an affect, it re-directs, but does so to all pages i.e the condition is ignored.



          RewriteEngine on

          RewriteCond %SCRIPT_FILENAME !-f
          :



          Because in a server context the request has not yet been mapped to the filesystem, so SCRIPT_FILENAME (or REQUEST_FILENAME) does not yet contain the full filesystem path (it simply contains the URL-path), so this condition always evaluates to true (the "URL-path" being tested is not a physical file - which is probably correct).



          You need to use a look-ahead instead in order to determine the final value. ie. %LA-U:REQUEST_FILENAME.



          So, in a server (or virtualhost) context you would need to use the following instead:



          RewriteEngine on

          RewriteCond %LA-U:REQUEST_FILENAME !-f
          RewriteCond %LA-U:REQUEST_FILENAME !-d

          RewriteRule ^/([^/]+)/?$ https://example.net?u=$1 [L,R=301]


          Note the slash prefix on the RewriteRule pattern.



          The NC flag is superfluous here.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 3 hours ago

























          answered 3 hours ago









          DocRoot

          1727




          1727







          • 1




            Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
            – Guesser
            2 hours ago












          • 1




            Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
            – Guesser
            2 hours ago







          1




          1




          Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
          – Guesser
          2 hours ago




          Thank you that all makes sense, however I would have not been able to work this out for a long time I'm sure. The final section did the trick.
          – Guesser
          2 hours ago










          Guesser is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          Guesser is a new contributor. Be nice, and check out our Code of Conduct.












          Guesser is a new contributor. Be nice, and check out our Code of Conduct.











          Guesser is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f937678%2frewritecond-ignored-in-httpd-conf%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery