not able to redirect from www.domain.com to domain.com in MVC C#












0















I am trying to redirect from website from https://www.example.com to https://example.com in ASP.NET MVC 5, but I am not able to do it, I am getting this error, when navigating to https://www.example.com



HTTP Error 404. The requested resource is not found.


I have tried to use the solution provided here



https://stackoverflow.com/a/3197446/3559462



https://stackoverflow.com/a/2178381/3559462



Currently my Web.Config has this code for url re-write



<rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="example.com" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:0}" />
</rule>


What is missing? It use to work previously but not now, why I am getting 404 suddenly and how to re-direct https://www.example.com to https://example.com without getting any error.



Do I need to register any DNS settings in my GoDaddy account? Or C#/web.config code can solve this error.



EDIT: when trying to use url https://example.com it works, here is the request/response headers image



headers










share|improve this question

























  • What happens when you load example.com in your browser?

    – mjwills
    Nov 13 '18 at 9:05











  • I had the same question... 404 usually means, that the ressource is not there. So have you tried example.com in your browser?

    – Andreas
    Nov 13 '18 at 9:06











  • @mjwills it is working fine, loading website and pages.

    – user3559462
    Nov 13 '18 at 9:06











  • Please load Chrome. Load Developer Tools, Network tab. Tick Preserve Log. Load example.com. Please show us the headers of the request and response.

    – mjwills
    Nov 13 '18 at 9:08













  • @mjwills done, added the image for request/response headers.

    – user3559462
    Nov 13 '18 at 9:15
















0















I am trying to redirect from website from https://www.example.com to https://example.com in ASP.NET MVC 5, but I am not able to do it, I am getting this error, when navigating to https://www.example.com



HTTP Error 404. The requested resource is not found.


I have tried to use the solution provided here



https://stackoverflow.com/a/3197446/3559462



https://stackoverflow.com/a/2178381/3559462



Currently my Web.Config has this code for url re-write



<rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="example.com" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:0}" />
</rule>


What is missing? It use to work previously but not now, why I am getting 404 suddenly and how to re-direct https://www.example.com to https://example.com without getting any error.



Do I need to register any DNS settings in my GoDaddy account? Or C#/web.config code can solve this error.



EDIT: when trying to use url https://example.com it works, here is the request/response headers image



headers










share|improve this question

























  • What happens when you load example.com in your browser?

    – mjwills
    Nov 13 '18 at 9:05











  • I had the same question... 404 usually means, that the ressource is not there. So have you tried example.com in your browser?

    – Andreas
    Nov 13 '18 at 9:06











  • @mjwills it is working fine, loading website and pages.

    – user3559462
    Nov 13 '18 at 9:06











  • Please load Chrome. Load Developer Tools, Network tab. Tick Preserve Log. Load example.com. Please show us the headers of the request and response.

    – mjwills
    Nov 13 '18 at 9:08













  • @mjwills done, added the image for request/response headers.

    – user3559462
    Nov 13 '18 at 9:15














0












0








0


1






I am trying to redirect from website from https://www.example.com to https://example.com in ASP.NET MVC 5, but I am not able to do it, I am getting this error, when navigating to https://www.example.com



HTTP Error 404. The requested resource is not found.


I have tried to use the solution provided here



https://stackoverflow.com/a/3197446/3559462



https://stackoverflow.com/a/2178381/3559462



Currently my Web.Config has this code for url re-write



<rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="example.com" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:0}" />
</rule>


What is missing? It use to work previously but not now, why I am getting 404 suddenly and how to re-direct https://www.example.com to https://example.com without getting any error.



Do I need to register any DNS settings in my GoDaddy account? Or C#/web.config code can solve this error.



EDIT: when trying to use url https://example.com it works, here is the request/response headers image



headers










share|improve this question
















I am trying to redirect from website from https://www.example.com to https://example.com in ASP.NET MVC 5, but I am not able to do it, I am getting this error, when navigating to https://www.example.com



HTTP Error 404. The requested resource is not found.


I have tried to use the solution provided here



https://stackoverflow.com/a/3197446/3559462



https://stackoverflow.com/a/2178381/3559462



Currently my Web.Config has this code for url re-write



<rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="example.com" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:0}" />
</rule>


What is missing? It use to work previously but not now, why I am getting 404 suddenly and how to re-direct https://www.example.com to https://example.com without getting any error.



Do I need to register any DNS settings in my GoDaddy account? Or C#/web.config code can solve this error.



EDIT: when trying to use url https://example.com it works, here is the request/response headers image



headers







c# asp.net-mvc web-config






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 9:14







user3559462

















asked Nov 13 '18 at 8:59









user3559462user3559462

5319




5319













  • What happens when you load example.com in your browser?

    – mjwills
    Nov 13 '18 at 9:05











  • I had the same question... 404 usually means, that the ressource is not there. So have you tried example.com in your browser?

    – Andreas
    Nov 13 '18 at 9:06











  • @mjwills it is working fine, loading website and pages.

    – user3559462
    Nov 13 '18 at 9:06











  • Please load Chrome. Load Developer Tools, Network tab. Tick Preserve Log. Load example.com. Please show us the headers of the request and response.

    – mjwills
    Nov 13 '18 at 9:08













  • @mjwills done, added the image for request/response headers.

    – user3559462
    Nov 13 '18 at 9:15



















  • What happens when you load example.com in your browser?

    – mjwills
    Nov 13 '18 at 9:05











  • I had the same question... 404 usually means, that the ressource is not there. So have you tried example.com in your browser?

    – Andreas
    Nov 13 '18 at 9:06











  • @mjwills it is working fine, loading website and pages.

    – user3559462
    Nov 13 '18 at 9:06











  • Please load Chrome. Load Developer Tools, Network tab. Tick Preserve Log. Load example.com. Please show us the headers of the request and response.

    – mjwills
    Nov 13 '18 at 9:08













  • @mjwills done, added the image for request/response headers.

    – user3559462
    Nov 13 '18 at 9:15

















What happens when you load example.com in your browser?

– mjwills
Nov 13 '18 at 9:05





What happens when you load example.com in your browser?

– mjwills
Nov 13 '18 at 9:05













I had the same question... 404 usually means, that the ressource is not there. So have you tried example.com in your browser?

– Andreas
Nov 13 '18 at 9:06





I had the same question... 404 usually means, that the ressource is not there. So have you tried example.com in your browser?

– Andreas
Nov 13 '18 at 9:06













@mjwills it is working fine, loading website and pages.

– user3559462
Nov 13 '18 at 9:06





@mjwills it is working fine, loading website and pages.

– user3559462
Nov 13 '18 at 9:06













Please load Chrome. Load Developer Tools, Network tab. Tick Preserve Log. Load example.com. Please show us the headers of the request and response.

– mjwills
Nov 13 '18 at 9:08







Please load Chrome. Load Developer Tools, Network tab. Tick Preserve Log. Load example.com. Please show us the headers of the request and response.

– mjwills
Nov 13 '18 at 9:08















@mjwills done, added the image for request/response headers.

– user3559462
Nov 13 '18 at 9:15





@mjwills done, added the image for request/response headers.

– user3559462
Nov 13 '18 at 9:15












1 Answer
1






active

oldest

votes


















0














I was able to solve this using these steps:




  1. Logged in into my GoDaddy DNS management page and added a new type "A" record with Host as "www" and To as "IP Address of website", TTL = 1 hour.

  2. After adding new DNS record, I logged into my server using Remote desktop and navigated to my website using IIS manager (Server->Sites (expand it) -> Select your website), Clicked on "Bindings" (inside right hand side panel, below "Edit")


Then added the new binding with values as
Type : https ,
host-name : www.example.com ,
Port : 443 ,
IP Address : IP Address of website,



That's it, after following above steps my problem got resolved and now website is redirected to https://example.com with 301 permanent redirect



Also please note the Web.Config settings (Performs redirect from www to non-www website), which I have already placed in the question, here it is again



<rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="example.com" negate="true" />
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://example.com/{R:0}" />
</rule>





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%2f53277227%2fnot-able-to-redirect-from-www-domain-com-to-domain-com-in-mvc-c-sharp%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














    I was able to solve this using these steps:




    1. Logged in into my GoDaddy DNS management page and added a new type "A" record with Host as "www" and To as "IP Address of website", TTL = 1 hour.

    2. After adding new DNS record, I logged into my server using Remote desktop and navigated to my website using IIS manager (Server->Sites (expand it) -> Select your website), Clicked on "Bindings" (inside right hand side panel, below "Edit")


    Then added the new binding with values as
    Type : https ,
    host-name : www.example.com ,
    Port : 443 ,
    IP Address : IP Address of website,



    That's it, after following above steps my problem got resolved and now website is redirected to https://example.com with 301 permanent redirect



    Also please note the Web.Config settings (Performs redirect from www to non-www website), which I have already placed in the question, here it is again



    <rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="example.com" negate="true" />
    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://example.com/{R:0}" />
    </rule>





    share|improve this answer




























      0














      I was able to solve this using these steps:




      1. Logged in into my GoDaddy DNS management page and added a new type "A" record with Host as "www" and To as "IP Address of website", TTL = 1 hour.

      2. After adding new DNS record, I logged into my server using Remote desktop and navigated to my website using IIS manager (Server->Sites (expand it) -> Select your website), Clicked on "Bindings" (inside right hand side panel, below "Edit")


      Then added the new binding with values as
      Type : https ,
      host-name : www.example.com ,
      Port : 443 ,
      IP Address : IP Address of website,



      That's it, after following above steps my problem got resolved and now website is redirected to https://example.com with 301 permanent redirect



      Also please note the Web.Config settings (Performs redirect from www to non-www website), which I have already placed in the question, here it is again



      <rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
      <match url="*" />
      <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="example.com" negate="true" />
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://example.com/{R:0}" />
      </rule>





      share|improve this answer


























        0












        0








        0







        I was able to solve this using these steps:




        1. Logged in into my GoDaddy DNS management page and added a new type "A" record with Host as "www" and To as "IP Address of website", TTL = 1 hour.

        2. After adding new DNS record, I logged into my server using Remote desktop and navigated to my website using IIS manager (Server->Sites (expand it) -> Select your website), Clicked on "Bindings" (inside right hand side panel, below "Edit")


        Then added the new binding with values as
        Type : https ,
        host-name : www.example.com ,
        Port : 443 ,
        IP Address : IP Address of website,



        That's it, after following above steps my problem got resolved and now website is redirected to https://example.com with 301 permanent redirect



        Also please note the Web.Config settings (Performs redirect from www to non-www website), which I have already placed in the question, here it is again



        <rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
        <match url="*" />
        <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="example.com" negate="true" />
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="https://example.com/{R:0}" />
        </rule>





        share|improve this answer













        I was able to solve this using these steps:




        1. Logged in into my GoDaddy DNS management page and added a new type "A" record with Host as "www" and To as "IP Address of website", TTL = 1 hour.

        2. After adding new DNS record, I logged into my server using Remote desktop and navigated to my website using IIS manager (Server->Sites (expand it) -> Select your website), Clicked on "Bindings" (inside right hand side panel, below "Edit")


        Then added the new binding with values as
        Type : https ,
        host-name : www.example.com ,
        Port : 443 ,
        IP Address : IP Address of website,



        That's it, after following above steps my problem got resolved and now website is redirected to https://example.com with 301 permanent redirect



        Also please note the Web.Config settings (Performs redirect from www to non-www website), which I have already placed in the question, here it is again



        <rule name="Redirect everything to https://example.com" patternSyntax="Wildcard" stopProcessing="true">
        <match url="*" />
        <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="example.com" negate="true" />
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="https://example.com/{R:0}" />
        </rule>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 8:57









        user3559462user3559462

        5319




        5319






























            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%2f53277227%2fnot-able-to-redirect-from-www-domain-com-to-domain-com-in-mvc-c-sharp%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

            Full-time equivalent

            Bicuculline

            さくらももこ