htaccess rewrite from http to https












2














Currently I redirect all http users (www or non-www) of upscfever.com to http://upscfever.com/upsc-fever/index.html



using



RewriteEngine on

RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "http://upscfever.com/upsc-fever/index.html" [R=301,L]


Now I want all users to shift to https so I modified as follows:



RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "https://upscfever.com/upsc-fever/index.html" [R=301,L]


So that all who type upscfever.com OR www.upscfever.com should go to
https://upscfever.com/upsc-fever/index.html - instead



Plus all links should be https. But its not working I get Page not found.










share|improve this question
























  • Just my curios, why you done let a tool like cerbot redirec all you request to https instead add an .htaccess file ? Some config like this root /var/www/upscfever.com/upsc-fever;
    – Truong Dang
    Nov 26 at 6:57


















2














Currently I redirect all http users (www or non-www) of upscfever.com to http://upscfever.com/upsc-fever/index.html



using



RewriteEngine on

RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "http://upscfever.com/upsc-fever/index.html" [R=301,L]


Now I want all users to shift to https so I modified as follows:



RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "https://upscfever.com/upsc-fever/index.html" [R=301,L]


So that all who type upscfever.com OR www.upscfever.com should go to
https://upscfever.com/upsc-fever/index.html - instead



Plus all links should be https. But its not working I get Page not found.










share|improve this question
























  • Just my curios, why you done let a tool like cerbot redirec all you request to https instead add an .htaccess file ? Some config like this root /var/www/upscfever.com/upsc-fever;
    – Truong Dang
    Nov 26 at 6:57
















2












2








2







Currently I redirect all http users (www or non-www) of upscfever.com to http://upscfever.com/upsc-fever/index.html



using



RewriteEngine on

RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "http://upscfever.com/upsc-fever/index.html" [R=301,L]


Now I want all users to shift to https so I modified as follows:



RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "https://upscfever.com/upsc-fever/index.html" [R=301,L]


So that all who type upscfever.com OR www.upscfever.com should go to
https://upscfever.com/upsc-fever/index.html - instead



Plus all links should be https. But its not working I get Page not found.










share|improve this question















Currently I redirect all http users (www or non-www) of upscfever.com to http://upscfever.com/upsc-fever/index.html



using



RewriteEngine on

RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "http://upscfever.com/upsc-fever/index.html" [R=301,L]


Now I want all users to shift to https so I modified as follows:



RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "https://upscfever.com/upsc-fever/index.html" [R=301,L]


So that all who type upscfever.com OR www.upscfever.com should go to
https://upscfever.com/upsc-fever/index.html - instead



Plus all links should be https. But its not working I get Page not found.







apache .htaccess






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 16:27

























asked Nov 18 at 15:35









pranav nerurkar

6711




6711












  • Just my curios, why you done let a tool like cerbot redirec all you request to https instead add an .htaccess file ? Some config like this root /var/www/upscfever.com/upsc-fever;
    – Truong Dang
    Nov 26 at 6:57




















  • Just my curios, why you done let a tool like cerbot redirec all you request to https instead add an .htaccess file ? Some config like this root /var/www/upscfever.com/upsc-fever;
    – Truong Dang
    Nov 26 at 6:57


















Just my curios, why you done let a tool like cerbot redirec all you request to https instead add an .htaccess file ? Some config like this root /var/www/upscfever.com/upsc-fever;
– Truong Dang
Nov 26 at 6:57






Just my curios, why you done let a tool like cerbot redirec all you request to https instead add an .htaccess file ? Some config like this root /var/www/upscfever.com/upsc-fever;
– Truong Dang
Nov 26 at 6:57














5 Answers
5






active

oldest

votes


















0














Your server has to setup the https first, depend on hosting vendor, if your hosting is vps you need to setup https for apache, install cert also.



You can find some instruction like this:



https://manual.seafile.com/deploy/https_with_apache.html



https://www.digicert.com/csr-ssl-installation/apache-openssl.htm






share|improve this answer





















  • all that is done. now the htaccess commands are only left
    – pranav nerurkar
    Nov 19 at 8:34



















0














I think you want to make 3 different changes:




  1. Change your .htaccess file to redirect requests to root to your custom index irrespective of the HTTPS or HTTP for the original request


RewriteEngine on

RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$
RewriteRule ^/?$ "https://%{SERVER_NAME}/upsc-fever/index.html" [R,L]


There is no R=301 part here because I'm not sure it is really wise to make permanent such a redirect to an obscure inner URL.




  1. Redirect all other non-HTTPS requests to HTTPS (preserving the rest of the URL):


RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.upscfever.com$

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]


Making this redirect permanent seems pretty safe.




  1. Change all internal links in all of your HTML pages (or whatever backend generates them) to use protocol-relative // prefix or explicitly https:// instead of current http://. Preserve the protocol for the external links as is.


As for troubleshooting, you may use the Network tab of the Chrome DevTools (F12) to see exact server reply (note: enabling "Preserve log" and "Disable cache" flags is useful in such context)



Chrome DevTools






share|improve this answer





























    0














    You can do that using a single rule as follows in your site root .htaccess:



    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^(?:www.)?upscfever.com$ [NC]
    RewriteRule ^/?$ /upsc-fever/index.html [R=301,L]


    This will redirect both http and https URLs.






    share|improve this answer





























      0














      You may try something like this:



      RewriteEngine On
      RewriteCond %{HTTP_HOST} !=""
      RewriteCond %{HTTP_HOST} !^www. [NC]
      RewriteCond %{HTTPS}s ^on(s)|
      RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]





      share|improve this answer





























        0














        I hope below code will do the work for you



        RewriteEngine On 
        RewriteCond %{HTTPS} !=on
        RewriteRule ^/?(.*) https://famebooking.net/$1 [R,L]


        just simply add above code in .htaccess below authorization header condition is written under RewriteEngine On



        Let me know if that helps.






        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%2f53362563%2fhtaccess-rewrite-from-http-to-https%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Your server has to setup the https first, depend on hosting vendor, if your hosting is vps you need to setup https for apache, install cert also.



          You can find some instruction like this:



          https://manual.seafile.com/deploy/https_with_apache.html



          https://www.digicert.com/csr-ssl-installation/apache-openssl.htm






          share|improve this answer





















          • all that is done. now the htaccess commands are only left
            – pranav nerurkar
            Nov 19 at 8:34
















          0














          Your server has to setup the https first, depend on hosting vendor, if your hosting is vps you need to setup https for apache, install cert also.



          You can find some instruction like this:



          https://manual.seafile.com/deploy/https_with_apache.html



          https://www.digicert.com/csr-ssl-installation/apache-openssl.htm






          share|improve this answer





















          • all that is done. now the htaccess commands are only left
            – pranav nerurkar
            Nov 19 at 8:34














          0












          0








          0






          Your server has to setup the https first, depend on hosting vendor, if your hosting is vps you need to setup https for apache, install cert also.



          You can find some instruction like this:



          https://manual.seafile.com/deploy/https_with_apache.html



          https://www.digicert.com/csr-ssl-installation/apache-openssl.htm






          share|improve this answer












          Your server has to setup the https first, depend on hosting vendor, if your hosting is vps you need to setup https for apache, install cert also.



          You can find some instruction like this:



          https://manual.seafile.com/deploy/https_with_apache.html



          https://www.digicert.com/csr-ssl-installation/apache-openssl.htm







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 18 at 16:35









          Mark Smith

          284




          284












          • all that is done. now the htaccess commands are only left
            – pranav nerurkar
            Nov 19 at 8:34


















          • all that is done. now the htaccess commands are only left
            – pranav nerurkar
            Nov 19 at 8:34
















          all that is done. now the htaccess commands are only left
          – pranav nerurkar
          Nov 19 at 8:34




          all that is done. now the htaccess commands are only left
          – pranav nerurkar
          Nov 19 at 8:34













          0














          I think you want to make 3 different changes:




          1. Change your .htaccess file to redirect requests to root to your custom index irrespective of the HTTPS or HTTP for the original request


          RewriteEngine on

          RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
          RewriteCond %{HTTP_HOST} ^www.upscfever.com$
          RewriteRule ^/?$ "https://%{SERVER_NAME}/upsc-fever/index.html" [R,L]


          There is no R=301 part here because I'm not sure it is really wise to make permanent such a redirect to an obscure inner URL.




          1. Redirect all other non-HTTPS requests to HTTPS (preserving the rest of the URL):


          RewriteCond %{HTTPS} !=on
          RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
          RewriteCond %{HTTP_HOST} ^www.upscfever.com$

          RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]


          Making this redirect permanent seems pretty safe.




          1. Change all internal links in all of your HTML pages (or whatever backend generates them) to use protocol-relative // prefix or explicitly https:// instead of current http://. Preserve the protocol for the external links as is.


          As for troubleshooting, you may use the Network tab of the Chrome DevTools (F12) to see exact server reply (note: enabling "Preserve log" and "Disable cache" flags is useful in such context)



          Chrome DevTools






          share|improve this answer


























            0














            I think you want to make 3 different changes:




            1. Change your .htaccess file to redirect requests to root to your custom index irrespective of the HTTPS or HTTP for the original request


            RewriteEngine on

            RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
            RewriteCond %{HTTP_HOST} ^www.upscfever.com$
            RewriteRule ^/?$ "https://%{SERVER_NAME}/upsc-fever/index.html" [R,L]


            There is no R=301 part here because I'm not sure it is really wise to make permanent such a redirect to an obscure inner URL.




            1. Redirect all other non-HTTPS requests to HTTPS (preserving the rest of the URL):


            RewriteCond %{HTTPS} !=on
            RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
            RewriteCond %{HTTP_HOST} ^www.upscfever.com$

            RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]


            Making this redirect permanent seems pretty safe.




            1. Change all internal links in all of your HTML pages (or whatever backend generates them) to use protocol-relative // prefix or explicitly https:// instead of current http://. Preserve the protocol for the external links as is.


            As for troubleshooting, you may use the Network tab of the Chrome DevTools (F12) to see exact server reply (note: enabling "Preserve log" and "Disable cache" flags is useful in such context)



            Chrome DevTools






            share|improve this answer
























              0












              0








              0






              I think you want to make 3 different changes:




              1. Change your .htaccess file to redirect requests to root to your custom index irrespective of the HTTPS or HTTP for the original request


              RewriteEngine on

              RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
              RewriteCond %{HTTP_HOST} ^www.upscfever.com$
              RewriteRule ^/?$ "https://%{SERVER_NAME}/upsc-fever/index.html" [R,L]


              There is no R=301 part here because I'm not sure it is really wise to make permanent such a redirect to an obscure inner URL.




              1. Redirect all other non-HTTPS requests to HTTPS (preserving the rest of the URL):


              RewriteCond %{HTTPS} !=on
              RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
              RewriteCond %{HTTP_HOST} ^www.upscfever.com$

              RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]


              Making this redirect permanent seems pretty safe.




              1. Change all internal links in all of your HTML pages (or whatever backend generates them) to use protocol-relative // prefix or explicitly https:// instead of current http://. Preserve the protocol for the external links as is.


              As for troubleshooting, you may use the Network tab of the Chrome DevTools (F12) to see exact server reply (note: enabling "Preserve log" and "Disable cache" flags is useful in such context)



              Chrome DevTools






              share|improve this answer












              I think you want to make 3 different changes:




              1. Change your .htaccess file to redirect requests to root to your custom index irrespective of the HTTPS or HTTP for the original request


              RewriteEngine on

              RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
              RewriteCond %{HTTP_HOST} ^www.upscfever.com$
              RewriteRule ^/?$ "https://%{SERVER_NAME}/upsc-fever/index.html" [R,L]


              There is no R=301 part here because I'm not sure it is really wise to make permanent such a redirect to an obscure inner URL.




              1. Redirect all other non-HTTPS requests to HTTPS (preserving the rest of the URL):


              RewriteCond %{HTTPS} !=on
              RewriteCond %{HTTP_HOST} ^upscfever.com$ [OR]
              RewriteCond %{HTTP_HOST} ^www.upscfever.com$

              RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]


              Making this redirect permanent seems pretty safe.




              1. Change all internal links in all of your HTML pages (or whatever backend generates them) to use protocol-relative // prefix or explicitly https:// instead of current http://. Preserve the protocol for the external links as is.


              As for troubleshooting, you may use the Network tab of the Chrome DevTools (F12) to see exact server reply (note: enabling "Preserve log" and "Disable cache" flags is useful in such context)



              Chrome DevTools







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 22 at 23:54









              SergGr

              19k22243




              19k22243























                  0














                  You can do that using a single rule as follows in your site root .htaccess:



                  RewriteEngine on

                  RewriteCond %{HTTP_HOST} ^(?:www.)?upscfever.com$ [NC]
                  RewriteRule ^/?$ /upsc-fever/index.html [R=301,L]


                  This will redirect both http and https URLs.






                  share|improve this answer


























                    0














                    You can do that using a single rule as follows in your site root .htaccess:



                    RewriteEngine on

                    RewriteCond %{HTTP_HOST} ^(?:www.)?upscfever.com$ [NC]
                    RewriteRule ^/?$ /upsc-fever/index.html [R=301,L]


                    This will redirect both http and https URLs.






                    share|improve this answer
























                      0












                      0








                      0






                      You can do that using a single rule as follows in your site root .htaccess:



                      RewriteEngine on

                      RewriteCond %{HTTP_HOST} ^(?:www.)?upscfever.com$ [NC]
                      RewriteRule ^/?$ /upsc-fever/index.html [R=301,L]


                      This will redirect both http and https URLs.






                      share|improve this answer












                      You can do that using a single rule as follows in your site root .htaccess:



                      RewriteEngine on

                      RewriteCond %{HTTP_HOST} ^(?:www.)?upscfever.com$ [NC]
                      RewriteRule ^/?$ /upsc-fever/index.html [R=301,L]


                      This will redirect both http and https URLs.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 24 at 5:48









                      anubhava

                      519k46316390




                      519k46316390























                          0














                          You may try something like this:



                          RewriteEngine On
                          RewriteCond %{HTTP_HOST} !=""
                          RewriteCond %{HTTP_HOST} !^www. [NC]
                          RewriteCond %{HTTPS}s ^on(s)|
                          RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]





                          share|improve this answer


























                            0














                            You may try something like this:



                            RewriteEngine On
                            RewriteCond %{HTTP_HOST} !=""
                            RewriteCond %{HTTP_HOST} !^www. [NC]
                            RewriteCond %{HTTPS}s ^on(s)|
                            RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]





                            share|improve this answer
























                              0












                              0








                              0






                              You may try something like this:



                              RewriteEngine On
                              RewriteCond %{HTTP_HOST} !=""
                              RewriteCond %{HTTP_HOST} !^www. [NC]
                              RewriteCond %{HTTPS}s ^on(s)|
                              RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]





                              share|improve this answer












                              You may try something like this:



                              RewriteEngine On
                              RewriteCond %{HTTP_HOST} !=""
                              RewriteCond %{HTTP_HOST} !^www. [NC]
                              RewriteCond %{HTTPS}s ^on(s)|
                              RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 26 at 20:03









                              UnP

                              7111




                              7111























                                  0














                                  I hope below code will do the work for you



                                  RewriteEngine On 
                                  RewriteCond %{HTTPS} !=on
                                  RewriteRule ^/?(.*) https://famebooking.net/$1 [R,L]


                                  just simply add above code in .htaccess below authorization header condition is written under RewriteEngine On



                                  Let me know if that helps.






                                  share|improve this answer


























                                    0














                                    I hope below code will do the work for you



                                    RewriteEngine On 
                                    RewriteCond %{HTTPS} !=on
                                    RewriteRule ^/?(.*) https://famebooking.net/$1 [R,L]


                                    just simply add above code in .htaccess below authorization header condition is written under RewriteEngine On



                                    Let me know if that helps.






                                    share|improve this answer
























                                      0












                                      0








                                      0






                                      I hope below code will do the work for you



                                      RewriteEngine On 
                                      RewriteCond %{HTTPS} !=on
                                      RewriteRule ^/?(.*) https://famebooking.net/$1 [R,L]


                                      just simply add above code in .htaccess below authorization header condition is written under RewriteEngine On



                                      Let me know if that helps.






                                      share|improve this answer












                                      I hope below code will do the work for you



                                      RewriteEngine On 
                                      RewriteCond %{HTTPS} !=on
                                      RewriteRule ^/?(.*) https://famebooking.net/$1 [R,L]


                                      just simply add above code in .htaccess below authorization header condition is written under RewriteEngine On



                                      Let me know if that helps.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 28 at 6:03









                                      Sandeep Garg

                                      330111




                                      330111






























                                          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.





                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • 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%2f53362563%2fhtaccess-rewrite-from-http-to-https%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

                                          Catalogne

                                          Violoncelliste

                                          Héron pourpré