Trace 301 Redirect Rule and move all request to www subdomain












0














I have a domain example.com added to the DigitalOcean (Ubuntu 16.04) with Apache2.4.18 and have Wordpress installed on it. The site is running properly.



The problem is, that all the request www.example.com redirects to example.com. I need example.com to redirect to www.example.com.



I see there are 2 ways to do it. 1. .htaccess and 2. Apache config file, currently using 000-default.conf file. I installed letsencrypt ssl, which added the following RewriteRule to 000-default.conf



RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


based on the research online, I did modify the 000-default.conf to



RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


and also tried the following code in .htaccess file.



RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]


Upon doing either of these, I get error of multiple redirection loop. Which basically redirecting example.com to www.example.com and www.example.com to example.com and so on. I tested the same on Redirectcheck.com.



The main issue is I can't seem to find out the first 301 Redirect which is all the request being redirected to exmple.com. If I can disable or overwrite the main 301 Redirect rule then I can achieve all the request to be redirected to www.example.com.



I did my research but I'm hitting my head hard here, any help would be really appreciated. Thank You!










share|improve this question



























    0














    I have a domain example.com added to the DigitalOcean (Ubuntu 16.04) with Apache2.4.18 and have Wordpress installed on it. The site is running properly.



    The problem is, that all the request www.example.com redirects to example.com. I need example.com to redirect to www.example.com.



    I see there are 2 ways to do it. 1. .htaccess and 2. Apache config file, currently using 000-default.conf file. I installed letsencrypt ssl, which added the following RewriteRule to 000-default.conf



    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.example.com [OR]
    RewriteCond %{SERVER_NAME} =example.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


    based on the research online, I did modify the 000-default.conf to



    RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


    and also tried the following code in .htaccess file.



    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]


    Upon doing either of these, I get error of multiple redirection loop. Which basically redirecting example.com to www.example.com and www.example.com to example.com and so on. I tested the same on Redirectcheck.com.



    The main issue is I can't seem to find out the first 301 Redirect which is all the request being redirected to exmple.com. If I can disable or overwrite the main 301 Redirect rule then I can achieve all the request to be redirected to www.example.com.



    I did my research but I'm hitting my head hard here, any help would be really appreciated. Thank You!










    share|improve this question

























      0












      0








      0







      I have a domain example.com added to the DigitalOcean (Ubuntu 16.04) with Apache2.4.18 and have Wordpress installed on it. The site is running properly.



      The problem is, that all the request www.example.com redirects to example.com. I need example.com to redirect to www.example.com.



      I see there are 2 ways to do it. 1. .htaccess and 2. Apache config file, currently using 000-default.conf file. I installed letsencrypt ssl, which added the following RewriteRule to 000-default.conf



      RewriteEngine on
      RewriteCond %{SERVER_NAME} =www.example.com [OR]
      RewriteCond %{SERVER_NAME} =example.com
      RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


      based on the research online, I did modify the 000-default.conf to



      RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


      and also tried the following code in .htaccess file.



      RewriteCond %{HTTP_HOST} !^www. [NC]
      RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]


      Upon doing either of these, I get error of multiple redirection loop. Which basically redirecting example.com to www.example.com and www.example.com to example.com and so on. I tested the same on Redirectcheck.com.



      The main issue is I can't seem to find out the first 301 Redirect which is all the request being redirected to exmple.com. If I can disable or overwrite the main 301 Redirect rule then I can achieve all the request to be redirected to www.example.com.



      I did my research but I'm hitting my head hard here, any help would be really appreciated. Thank You!










      share|improve this question













      I have a domain example.com added to the DigitalOcean (Ubuntu 16.04) with Apache2.4.18 and have Wordpress installed on it. The site is running properly.



      The problem is, that all the request www.example.com redirects to example.com. I need example.com to redirect to www.example.com.



      I see there are 2 ways to do it. 1. .htaccess and 2. Apache config file, currently using 000-default.conf file. I installed letsencrypt ssl, which added the following RewriteRule to 000-default.conf



      RewriteEngine on
      RewriteCond %{SERVER_NAME} =www.example.com [OR]
      RewriteCond %{SERVER_NAME} =example.com
      RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


      based on the research online, I did modify the 000-default.conf to



      RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


      and also tried the following code in .htaccess file.



      RewriteCond %{HTTP_HOST} !^www. [NC]
      RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]


      Upon doing either of these, I get error of multiple redirection loop. Which basically redirecting example.com to www.example.com and www.example.com to example.com and so on. I tested the same on Redirectcheck.com.



      The main issue is I can't seem to find out the first 301 Redirect which is all the request being redirected to exmple.com. If I can disable or overwrite the main 301 Redirect rule then I can achieve all the request to be redirected to www.example.com.



      I did my research but I'm hitting my head hard here, any help would be really appreciated. Thank You!







      apache .htaccess redirect






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 at 9:02









      Dilip Gupta

      2615




      2615
























          1 Answer
          1






          active

          oldest

          votes


















          0














          So, I finally traced it down, all the configuration were correct, the only issue was in the WordPress -> Admin Panel -> Setting -> General. I have placed the site_url and main_url as example.com and when I updated it to www.example.com and tested again, It did fix it.






          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%2f53443474%2ftrace-301-redirect-rule-and-move-all-request-to-www-subdomain%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














            So, I finally traced it down, all the configuration were correct, the only issue was in the WordPress -> Admin Panel -> Setting -> General. I have placed the site_url and main_url as example.com and when I updated it to www.example.com and tested again, It did fix it.






            share|improve this answer


























              0














              So, I finally traced it down, all the configuration were correct, the only issue was in the WordPress -> Admin Panel -> Setting -> General. I have placed the site_url and main_url as example.com and when I updated it to www.example.com and tested again, It did fix it.






              share|improve this answer
























                0












                0








                0






                So, I finally traced it down, all the configuration were correct, the only issue was in the WordPress -> Admin Panel -> Setting -> General. I have placed the site_url and main_url as example.com and when I updated it to www.example.com and tested again, It did fix it.






                share|improve this answer












                So, I finally traced it down, all the configuration were correct, the only issue was in the WordPress -> Admin Panel -> Setting -> General. I have placed the site_url and main_url as example.com and when I updated it to www.example.com and tested again, It did fix it.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 at 11:09









                Dilip Gupta

                2615




                2615






























                    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%2f53443474%2ftrace-301-redirect-rule-and-move-all-request-to-www-subdomain%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

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)