.htaccess rewriterule if/elsemod_rewrite: url rewriting plus subdomain (wildcard) rewrite at the same...

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

When is "ei" a diphthong?

Does Doodling or Improvising on the Piano Have Any Benefits?

If Captain Marvel (MCU) were to have a child with a human male, would the child be human or Kree?

Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?

How to reduce predictors the right way for a logistic regression model

Can I say "fingers" when referring to toes?

Can I cause damage to electrical appliances by unplugging them when they are turned on?

Does the Crossbow Expert feat's extra crossbow attack work with the reaction attack from a Hunter ranger's Giant Killer feature?

Mimic lecturing on blackboard, facing audience

Showing mass murder in a kid's book

Should I warn new/prospective PhD Student that supervisor is terrible?

Did I make a mistake by ccing email to boss to others?

Why would five hundred and five be same as one?

El Dorado Word Puzzle II: Videogame Edition

"Oh no!" in Latin

Check if object is null and return null

Why didn't Voldemort know what Grindelwald looked like?

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Would this string work as string?

Integral Notations in Quantum Mechanics

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

What the heck is gets(stdin) on site coderbyte?

What does "tick" mean in this sentence?



.htaccess rewriterule if/else


mod_rewrite: url rewriting plus subdomain (wildcard) rewrite at the same time.htaccess RewriteRule ProblemIndex File in .htaccessDebian etch mod rewrite problemWhich directive could make apache/rewrite redirect products/ to products.phpMod_rewite - do these rewrite rules work?Difference b/w .htaccess and example.com.confrewrite rule does not rewrite url as expected.htaccess not behaving as desiredA specific issue with Apache 2.2 URL rewriting













2















I have the following .htaccess code:



RewriteEngine on

<if "%{HTTP_HOST} =~ /^helpdesk./">
RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
</if>

<if "%{HTTP_HOST} =~ /^account./">
RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]
</if>


Obviously, this is not working.



What I want to achieve:



when I go to http://helpdesk.domain.com, the index.php file must get the parameters pages=helpdesk and file=index. When I go to http://account.domain.com the index.php file must get the parameters pages=account and file=index.



When I replace the RewriteRule with a redirect, it works, but is this possible to achieve?



Thanks in advance!



Edit:



asked my question way to fast. This works.



RewriteEngine on
RewriteCond %{HTTP_HOST} ^helpdesk..* [NC]
RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
RewriteCond %{HTTP_HOST} ^account..* [NC]
RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]


But is this the correct way or is there a (better) alternative?










share|improve this question
















bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    2















    I have the following .htaccess code:



    RewriteEngine on

    <if "%{HTTP_HOST} =~ /^helpdesk./">
    RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
    </if>

    <if "%{HTTP_HOST} =~ /^account./">
    RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]
    </if>


    Obviously, this is not working.



    What I want to achieve:



    when I go to http://helpdesk.domain.com, the index.php file must get the parameters pages=helpdesk and file=index. When I go to http://account.domain.com the index.php file must get the parameters pages=account and file=index.



    When I replace the RewriteRule with a redirect, it works, but is this possible to achieve?



    Thanks in advance!



    Edit:



    asked my question way to fast. This works.



    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^helpdesk..* [NC]
    RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
    RewriteCond %{HTTP_HOST} ^account..* [NC]
    RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]


    But is this the correct way or is there a (better) alternative?










    share|improve this question
















    bumped to the homepage by Community 10 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      2












      2








      2








      I have the following .htaccess code:



      RewriteEngine on

      <if "%{HTTP_HOST} =~ /^helpdesk./">
      RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
      </if>

      <if "%{HTTP_HOST} =~ /^account./">
      RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]
      </if>


      Obviously, this is not working.



      What I want to achieve:



      when I go to http://helpdesk.domain.com, the index.php file must get the parameters pages=helpdesk and file=index. When I go to http://account.domain.com the index.php file must get the parameters pages=account and file=index.



      When I replace the RewriteRule with a redirect, it works, but is this possible to achieve?



      Thanks in advance!



      Edit:



      asked my question way to fast. This works.



      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^helpdesk..* [NC]
      RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
      RewriteCond %{HTTP_HOST} ^account..* [NC]
      RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]


      But is this the correct way or is there a (better) alternative?










      share|improve this question
















      I have the following .htaccess code:



      RewriteEngine on

      <if "%{HTTP_HOST} =~ /^helpdesk./">
      RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
      </if>

      <if "%{HTTP_HOST} =~ /^account./">
      RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]
      </if>


      Obviously, this is not working.



      What I want to achieve:



      when I go to http://helpdesk.domain.com, the index.php file must get the parameters pages=helpdesk and file=index. When I go to http://account.domain.com the index.php file must get the parameters pages=account and file=index.



      When I replace the RewriteRule with a redirect, it works, but is this possible to achieve?



      Thanks in advance!



      Edit:



      asked my question way to fast. This works.



      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^helpdesk..* [NC]
      RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
      RewriteCond %{HTTP_HOST} ^account..* [NC]
      RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]


      But is this the correct way or is there a (better) alternative?







      .htaccess mod-rewrite






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 14 '18 at 11:00







      yesterday

















      asked Jul 14 '18 at 10:55









      yesterdayyesterday

      113




      113





      bumped to the homepage by Community 10 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 10 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          What you are trying to achieve is possible with both, and your currently working configuration is the traditional way of doing this. That's why there's plenty of examples for doing this with RewriteCond. The Expressions and directives If, ElseIf, Else and were introduced in Apache 2.4 as a long-awaited feature, and one of the first examples is to make rewriting more readable and predictable:




          Some of the things you might use this directive for, you've been using
          mod_rewrite for up until now, so one of the side-effects of this
          directive is that we can reduce our reliance on mod_rewrite's complex
          syntax for common situations. Over the coming months, more examples
          will be added to the documentation, and we'll have a recipe section
          with many of the same sorts of scenarios that are in the mod_rewrite
          recipe section.



          In fact, most of the commonest uses of mod_rewrite can now be replaced
          with the If directive, making them easier to read, and, therefore,
          less prone to error, and the redirect looping that so often plagues
          RewriteRule-based solutions.




          Without testing, I'd say that using regular expressions with your use case makes this overly complicated. Because you are comparing Host: headers probably within a fixed domain, say example.com, you could use simple == (string equality) comparison operator instead of =~ (string matches the regular expression):



          <ifModule mod_rewrite.c>
          RewriteEngine on
          <If "%{HTTP_HOST} == 'helpdesk.example.com'">
          RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
          </If>
          <If "%{HTTP_HOST} == 'account.example.com'">
          RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]
          </If>
          </ifModule>





          share|improve this answer























            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',
            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%2fserverfault.com%2fquestions%2f920930%2fhtaccess-rewriterule-if-else%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            What you are trying to achieve is possible with both, and your currently working configuration is the traditional way of doing this. That's why there's plenty of examples for doing this with RewriteCond. The Expressions and directives If, ElseIf, Else and were introduced in Apache 2.4 as a long-awaited feature, and one of the first examples is to make rewriting more readable and predictable:




            Some of the things you might use this directive for, you've been using
            mod_rewrite for up until now, so one of the side-effects of this
            directive is that we can reduce our reliance on mod_rewrite's complex
            syntax for common situations. Over the coming months, more examples
            will be added to the documentation, and we'll have a recipe section
            with many of the same sorts of scenarios that are in the mod_rewrite
            recipe section.



            In fact, most of the commonest uses of mod_rewrite can now be replaced
            with the If directive, making them easier to read, and, therefore,
            less prone to error, and the redirect looping that so often plagues
            RewriteRule-based solutions.




            Without testing, I'd say that using regular expressions with your use case makes this overly complicated. Because you are comparing Host: headers probably within a fixed domain, say example.com, you could use simple == (string equality) comparison operator instead of =~ (string matches the regular expression):



            <ifModule mod_rewrite.c>
            RewriteEngine on
            <If "%{HTTP_HOST} == 'helpdesk.example.com'">
            RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
            </If>
            <If "%{HTTP_HOST} == 'account.example.com'">
            RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]
            </If>
            </ifModule>





            share|improve this answer




























              0














              What you are trying to achieve is possible with both, and your currently working configuration is the traditional way of doing this. That's why there's plenty of examples for doing this with RewriteCond. The Expressions and directives If, ElseIf, Else and were introduced in Apache 2.4 as a long-awaited feature, and one of the first examples is to make rewriting more readable and predictable:




              Some of the things you might use this directive for, you've been using
              mod_rewrite for up until now, so one of the side-effects of this
              directive is that we can reduce our reliance on mod_rewrite's complex
              syntax for common situations. Over the coming months, more examples
              will be added to the documentation, and we'll have a recipe section
              with many of the same sorts of scenarios that are in the mod_rewrite
              recipe section.



              In fact, most of the commonest uses of mod_rewrite can now be replaced
              with the If directive, making them easier to read, and, therefore,
              less prone to error, and the redirect looping that so often plagues
              RewriteRule-based solutions.




              Without testing, I'd say that using regular expressions with your use case makes this overly complicated. Because you are comparing Host: headers probably within a fixed domain, say example.com, you could use simple == (string equality) comparison operator instead of =~ (string matches the regular expression):



              <ifModule mod_rewrite.c>
              RewriteEngine on
              <If "%{HTTP_HOST} == 'helpdesk.example.com'">
              RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
              </If>
              <If "%{HTTP_HOST} == 'account.example.com'">
              RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]
              </If>
              </ifModule>





              share|improve this answer


























                0












                0








                0







                What you are trying to achieve is possible with both, and your currently working configuration is the traditional way of doing this. That's why there's plenty of examples for doing this with RewriteCond. The Expressions and directives If, ElseIf, Else and were introduced in Apache 2.4 as a long-awaited feature, and one of the first examples is to make rewriting more readable and predictable:




                Some of the things you might use this directive for, you've been using
                mod_rewrite for up until now, so one of the side-effects of this
                directive is that we can reduce our reliance on mod_rewrite's complex
                syntax for common situations. Over the coming months, more examples
                will be added to the documentation, and we'll have a recipe section
                with many of the same sorts of scenarios that are in the mod_rewrite
                recipe section.



                In fact, most of the commonest uses of mod_rewrite can now be replaced
                with the If directive, making them easier to read, and, therefore,
                less prone to error, and the redirect looping that so often plagues
                RewriteRule-based solutions.




                Without testing, I'd say that using regular expressions with your use case makes this overly complicated. Because you are comparing Host: headers probably within a fixed domain, say example.com, you could use simple == (string equality) comparison operator instead of =~ (string matches the regular expression):



                <ifModule mod_rewrite.c>
                RewriteEngine on
                <If "%{HTTP_HOST} == 'helpdesk.example.com'">
                RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
                </If>
                <If "%{HTTP_HOST} == 'account.example.com'">
                RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]
                </If>
                </ifModule>





                share|improve this answer













                What you are trying to achieve is possible with both, and your currently working configuration is the traditional way of doing this. That's why there's plenty of examples for doing this with RewriteCond. The Expressions and directives If, ElseIf, Else and were introduced in Apache 2.4 as a long-awaited feature, and one of the first examples is to make rewriting more readable and predictable:




                Some of the things you might use this directive for, you've been using
                mod_rewrite for up until now, so one of the side-effects of this
                directive is that we can reduce our reliance on mod_rewrite's complex
                syntax for common situations. Over the coming months, more examples
                will be added to the documentation, and we'll have a recipe section
                with many of the same sorts of scenarios that are in the mod_rewrite
                recipe section.



                In fact, most of the commonest uses of mod_rewrite can now be replaced
                with the If directive, making them easier to read, and, therefore,
                less prone to error, and the redirect looping that so often plagues
                RewriteRule-based solutions.




                Without testing, I'd say that using regular expressions with your use case makes this overly complicated. Because you are comparing Host: headers probably within a fixed domain, say example.com, you could use simple == (string equality) comparison operator instead of =~ (string matches the regular expression):



                <ifModule mod_rewrite.c>
                RewriteEngine on
                <If "%{HTTP_HOST} == 'helpdesk.example.com'">
                RewriteRule ^/?$ /index.php?pages=helpdesk&file=index [NC,L,QSA]
                </If>
                <If "%{HTTP_HOST} == 'account.example.com'">
                RewriteRule ^/?$ /index.php?pages=account&file=index [NC,L,QSA]
                </If>
                </ifModule>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 14 '18 at 12:48









                Esa JokinenEsa Jokinen

                23.5k23359




                23.5k23359






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Server Fault!


                    • 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%2fserverfault.com%2fquestions%2f920930%2fhtaccess-rewriterule-if-else%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







                    Popular posts from this blog

                    As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

                    Список ссавців Італії Природоохоронні статуси | Список |...

                    Українські прізвища Зміст Історичні відомості |...