.htaccess redirects to remove php and redirect to https and non-www












3















I have the following in my .htaccess file to




  • Remove www

  • Redirect to https

  • remove .php


This is my .htaccess:



# ----------------------------------------------------------------------
# | Redirect to HTTPS & remove www |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

# ----------------------------------------------------------------------
# | Remove .php extension |
# ----------------------------------------------------------------------
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]


When I view the site in Firefox I get the following error:




The page isn't redirecting properly.
This problem can sometimes be caused by disabling or refusing to accept cookies




And Chrome warns about too many redirects



The URL is updated to what I would expect (www removed and https added). There are no other redirects in effect



Can anyone spot where I am going wrong?










share|improve this question




















  • 1





    I can't see anything that would cause a redirect loop. There must be something in conflict, like other rules ? Could you tell what url the redirect loop generates ? That'd help to debug it

    – Justin Iurman
    Nov 14 '18 at 11:15













  • Hi Justin - url generated is correct, and there are no other redirect rules. I have updated the question to include this information

    – Mike Harrison
    Nov 15 '18 at 9:13











  • Actually, what you see is not what you get, proof is the redirect loop. Could you look in the network console of Chrome to see what's wrong ? This way, we'll see what's the redirect loop and we could determine the source of the problem. High is the chance that you have a CMS (do you ?) that is configured to accept http or www (or both) only, which would explain the redirect loop.

    – Justin Iurman
    Nov 15 '18 at 11:20













  • What is your Apache version? Try replacing RewriteCond %{HTTPS} off [OR] wiithRewriteCond %{REQUEST_SCHEME} =http

    – anubhava
    Nov 17 '18 at 12:44











  • check this question stackoverflow.com/questions/43242712/…

    – amin saffar
    Nov 19 '18 at 9:34
















3















I have the following in my .htaccess file to




  • Remove www

  • Redirect to https

  • remove .php


This is my .htaccess:



# ----------------------------------------------------------------------
# | Redirect to HTTPS & remove www |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

# ----------------------------------------------------------------------
# | Remove .php extension |
# ----------------------------------------------------------------------
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]


When I view the site in Firefox I get the following error:




The page isn't redirecting properly.
This problem can sometimes be caused by disabling or refusing to accept cookies




And Chrome warns about too many redirects



The URL is updated to what I would expect (www removed and https added). There are no other redirects in effect



Can anyone spot where I am going wrong?










share|improve this question




















  • 1





    I can't see anything that would cause a redirect loop. There must be something in conflict, like other rules ? Could you tell what url the redirect loop generates ? That'd help to debug it

    – Justin Iurman
    Nov 14 '18 at 11:15













  • Hi Justin - url generated is correct, and there are no other redirect rules. I have updated the question to include this information

    – Mike Harrison
    Nov 15 '18 at 9:13











  • Actually, what you see is not what you get, proof is the redirect loop. Could you look in the network console of Chrome to see what's wrong ? This way, we'll see what's the redirect loop and we could determine the source of the problem. High is the chance that you have a CMS (do you ?) that is configured to accept http or www (or both) only, which would explain the redirect loop.

    – Justin Iurman
    Nov 15 '18 at 11:20













  • What is your Apache version? Try replacing RewriteCond %{HTTPS} off [OR] wiithRewriteCond %{REQUEST_SCHEME} =http

    – anubhava
    Nov 17 '18 at 12:44











  • check this question stackoverflow.com/questions/43242712/…

    – amin saffar
    Nov 19 '18 at 9:34














3












3








3








I have the following in my .htaccess file to




  • Remove www

  • Redirect to https

  • remove .php


This is my .htaccess:



# ----------------------------------------------------------------------
# | Redirect to HTTPS & remove www |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

# ----------------------------------------------------------------------
# | Remove .php extension |
# ----------------------------------------------------------------------
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]


When I view the site in Firefox I get the following error:




The page isn't redirecting properly.
This problem can sometimes be caused by disabling or refusing to accept cookies




And Chrome warns about too many redirects



The URL is updated to what I would expect (www removed and https added). There are no other redirects in effect



Can anyone spot where I am going wrong?










share|improve this question
















I have the following in my .htaccess file to




  • Remove www

  • Redirect to https

  • remove .php


This is my .htaccess:



# ----------------------------------------------------------------------
# | Redirect to HTTPS & remove www |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

# ----------------------------------------------------------------------
# | Remove .php extension |
# ----------------------------------------------------------------------
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]


When I view the site in Firefox I get the following error:




The page isn't redirecting properly.
This problem can sometimes be caused by disabling or refusing to accept cookies




And Chrome warns about too many redirects



The URL is updated to what I would expect (www removed and https added). There are no other redirects in effect



Can anyone spot where I am going wrong?







.htaccess






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 9:13







Mike Harrison

















asked Nov 8 '18 at 10:57









Mike HarrisonMike Harrison

5851625




5851625








  • 1





    I can't see anything that would cause a redirect loop. There must be something in conflict, like other rules ? Could you tell what url the redirect loop generates ? That'd help to debug it

    – Justin Iurman
    Nov 14 '18 at 11:15













  • Hi Justin - url generated is correct, and there are no other redirect rules. I have updated the question to include this information

    – Mike Harrison
    Nov 15 '18 at 9:13











  • Actually, what you see is not what you get, proof is the redirect loop. Could you look in the network console of Chrome to see what's wrong ? This way, we'll see what's the redirect loop and we could determine the source of the problem. High is the chance that you have a CMS (do you ?) that is configured to accept http or www (or both) only, which would explain the redirect loop.

    – Justin Iurman
    Nov 15 '18 at 11:20













  • What is your Apache version? Try replacing RewriteCond %{HTTPS} off [OR] wiithRewriteCond %{REQUEST_SCHEME} =http

    – anubhava
    Nov 17 '18 at 12:44











  • check this question stackoverflow.com/questions/43242712/…

    – amin saffar
    Nov 19 '18 at 9:34














  • 1





    I can't see anything that would cause a redirect loop. There must be something in conflict, like other rules ? Could you tell what url the redirect loop generates ? That'd help to debug it

    – Justin Iurman
    Nov 14 '18 at 11:15













  • Hi Justin - url generated is correct, and there are no other redirect rules. I have updated the question to include this information

    – Mike Harrison
    Nov 15 '18 at 9:13











  • Actually, what you see is not what you get, proof is the redirect loop. Could you look in the network console of Chrome to see what's wrong ? This way, we'll see what's the redirect loop and we could determine the source of the problem. High is the chance that you have a CMS (do you ?) that is configured to accept http or www (or both) only, which would explain the redirect loop.

    – Justin Iurman
    Nov 15 '18 at 11:20













  • What is your Apache version? Try replacing RewriteCond %{HTTPS} off [OR] wiithRewriteCond %{REQUEST_SCHEME} =http

    – anubhava
    Nov 17 '18 at 12:44











  • check this question stackoverflow.com/questions/43242712/…

    – amin saffar
    Nov 19 '18 at 9:34








1




1





I can't see anything that would cause a redirect loop. There must be something in conflict, like other rules ? Could you tell what url the redirect loop generates ? That'd help to debug it

– Justin Iurman
Nov 14 '18 at 11:15







I can't see anything that would cause a redirect loop. There must be something in conflict, like other rules ? Could you tell what url the redirect loop generates ? That'd help to debug it

– Justin Iurman
Nov 14 '18 at 11:15















Hi Justin - url generated is correct, and there are no other redirect rules. I have updated the question to include this information

– Mike Harrison
Nov 15 '18 at 9:13





Hi Justin - url generated is correct, and there are no other redirect rules. I have updated the question to include this information

– Mike Harrison
Nov 15 '18 at 9:13













Actually, what you see is not what you get, proof is the redirect loop. Could you look in the network console of Chrome to see what's wrong ? This way, we'll see what's the redirect loop and we could determine the source of the problem. High is the chance that you have a CMS (do you ?) that is configured to accept http or www (or both) only, which would explain the redirect loop.

– Justin Iurman
Nov 15 '18 at 11:20







Actually, what you see is not what you get, proof is the redirect loop. Could you look in the network console of Chrome to see what's wrong ? This way, we'll see what's the redirect loop and we could determine the source of the problem. High is the chance that you have a CMS (do you ?) that is configured to accept http or www (or both) only, which would explain the redirect loop.

– Justin Iurman
Nov 15 '18 at 11:20















What is your Apache version? Try replacing RewriteCond %{HTTPS} off [OR] wiithRewriteCond %{REQUEST_SCHEME} =http

– anubhava
Nov 17 '18 at 12:44





What is your Apache version? Try replacing RewriteCond %{HTTPS} off [OR] wiithRewriteCond %{REQUEST_SCHEME} =http

– anubhava
Nov 17 '18 at 12:44













check this question stackoverflow.com/questions/43242712/…

– amin saffar
Nov 19 '18 at 9:34





check this question stackoverflow.com/questions/43242712/…

– amin saffar
Nov 19 '18 at 9:34












2 Answers
2






active

oldest

votes


















-1














It looks like you will want the following in your .htaccess file:



# ----------------------------------------------------------------------
# | Redirect to HTTPS & remove www |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.*)$ [OR]
RewriteCond %{https} off
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

# ----------------------------------------------------------------------
# | Remove .php extension |
# ----------------------------------------------------------------------
RewriteRule ^(.+).php$ /$1 [NC,L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ /$1.php [END]


This was borrowed from the accepted answer to the following similar topic:



.htaccess - Remove www, force https, remove php and remove trailing slash






share|improve this answer































    -1














    Try below code in your .htaccess file:



    RewritEengine on
    Options +FollowSymlinks
    RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
    RewriteRule ^(.*)$ https://example.com/$1 [r=301,nc]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^.]+)$ $1.php [NC,L]





    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%2f53206318%2fhtaccess-redirects-to-remove-php-and-redirect-to-https-and-non-www%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      -1














      It looks like you will want the following in your .htaccess file:



      # ----------------------------------------------------------------------
      # | Redirect to HTTPS & remove www |
      # ----------------------------------------------------------------------
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^www.(.*)$ [OR]
      RewriteCond %{https} off
      RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

      # ----------------------------------------------------------------------
      # | Remove .php extension |
      # ----------------------------------------------------------------------
      RewriteRule ^(.+).php$ /$1 [NC,L,R=301]
      RewriteCond %{REQUEST_FILENAME}.php -f
      RewriteRule ^(.+)/?$ /$1.php [END]


      This was borrowed from the accepted answer to the following similar topic:



      .htaccess - Remove www, force https, remove php and remove trailing slash






      share|improve this answer




























        -1














        It looks like you will want the following in your .htaccess file:



        # ----------------------------------------------------------------------
        # | Redirect to HTTPS & remove www |
        # ----------------------------------------------------------------------
        <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{HTTP_HOST} ^www.(.*)$ [OR]
        RewriteCond %{https} off
        RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

        # ----------------------------------------------------------------------
        # | Remove .php extension |
        # ----------------------------------------------------------------------
        RewriteRule ^(.+).php$ /$1 [NC,L,R=301]
        RewriteCond %{REQUEST_FILENAME}.php -f
        RewriteRule ^(.+)/?$ /$1.php [END]


        This was borrowed from the accepted answer to the following similar topic:



        .htaccess - Remove www, force https, remove php and remove trailing slash






        share|improve this answer


























          -1












          -1








          -1







          It looks like you will want the following in your .htaccess file:



          # ----------------------------------------------------------------------
          # | Redirect to HTTPS & remove www |
          # ----------------------------------------------------------------------
          <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteCond %{HTTP_HOST} ^www.(.*)$ [OR]
          RewriteCond %{https} off
          RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

          # ----------------------------------------------------------------------
          # | Remove .php extension |
          # ----------------------------------------------------------------------
          RewriteRule ^(.+).php$ /$1 [NC,L,R=301]
          RewriteCond %{REQUEST_FILENAME}.php -f
          RewriteRule ^(.+)/?$ /$1.php [END]


          This was borrowed from the accepted answer to the following similar topic:



          .htaccess - Remove www, force https, remove php and remove trailing slash






          share|improve this answer













          It looks like you will want the following in your .htaccess file:



          # ----------------------------------------------------------------------
          # | Redirect to HTTPS & remove www |
          # ----------------------------------------------------------------------
          <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteCond %{HTTP_HOST} ^www.(.*)$ [OR]
          RewriteCond %{https} off
          RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

          # ----------------------------------------------------------------------
          # | Remove .php extension |
          # ----------------------------------------------------------------------
          RewriteRule ^(.+).php$ /$1 [NC,L,R=301]
          RewriteCond %{REQUEST_FILENAME}.php -f
          RewriteRule ^(.+)/?$ /$1.php [END]


          This was borrowed from the accepted answer to the following similar topic:



          .htaccess - Remove www, force https, remove php and remove trailing slash







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 13:27









          Justin T.Justin T.

          597313




          597313

























              -1














              Try below code in your .htaccess file:



              RewritEengine on
              Options +FollowSymlinks
              RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
              RewriteRule ^(.*)$ https://example.com/$1 [r=301,nc]

              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteRule ^([^.]+)$ $1.php [NC,L]





              share|improve this answer




























                -1














                Try below code in your .htaccess file:



                RewritEengine on
                Options +FollowSymlinks
                RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
                RewriteRule ^(.*)$ https://example.com/$1 [r=301,nc]

                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^([^.]+)$ $1.php [NC,L]





                share|improve this answer


























                  -1












                  -1








                  -1







                  Try below code in your .htaccess file:



                  RewritEengine on
                  Options +FollowSymlinks
                  RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
                  RewriteRule ^(.*)$ https://example.com/$1 [r=301,nc]

                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteRule ^([^.]+)$ $1.php [NC,L]





                  share|improve this answer













                  Try below code in your .htaccess file:



                  RewritEengine on
                  Options +FollowSymlinks
                  RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
                  RewriteRule ^(.*)$ https://example.com/$1 [r=301,nc]

                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteRule ^([^.]+)$ $1.php [NC,L]






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 7:31









                  Muhammad TariqueMuhammad Tarique

                  457612




                  457612






























                      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%2f53206318%2fhtaccess-redirects-to-remove-php-and-redirect-to-https-and-non-www%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

                      How to send String Array data to Server using php in android

                      Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                      Is anime1.com a legal site for watching anime?