locked
web.config redirect random urls. RRS feed

  • Question

  • User919049477 posted

    I need to make a web.config file that will redirect all request that is not a actually page to the home page. So if someone tries to come to my site http://domain.com/dalkdsnfsn they will be taken to the home page. I have tried quite a few rules and cant seem to get it to work for anything.

    Just need any calling to the site that is not of a page that is actually on the site to be redirected to home page. Can someone please help me.

    Wednesday, June 5, 2013 7:05 PM

Answers

  • User281315223 posted

    Try adding the following code to your web.config, which should handle the appropriate redirect (even in the case of non-existing URLs) : 

    <system.webServer>
        <httpErrors existingResponse="Replace" errorMode="Custom">
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" prefixLanguageFilePath="" path="/YourRedirectLocation.aspx" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>

    (Related Stack Overflow)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 9, 2013 9:04 AM
  • User-801004448 posted

    It's on a shared server so we aren't capable of achieving this since we can't access any modules on the server..

    Do you have IIS on your local computer? Create a website and configure 404 error, test on your local computer, then copy 404 configuration in web.config file to shared host server.

    You can also ask your host to configure 404 error for you. It can be done quickly.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 12, 2013 11:03 PM

All replies

  • User-1716253493 posted
    Try redirect to "~/" or Try redirect to "~/Default.aspx"
    Wednesday, June 5, 2013 8:13 PM
  • User476696664 posted

    I am having a struggle with the original post with this since I do work for him. We both can't figure out how to use this or anything about web.config

    What we need is:

    Random url's to be redirected back to your index page.

    Example: http://mydomain.com/123 (non-existant) therefore it redirects back to http://mydomain.com/

    I need this method via web.config because the site is hosting on an IIS server that doesn't allow .htaccess.

    -Newelly 

    Wednesday, June 5, 2013 8:21 PM
  • User-801004448 posted

    It should be a 404 redirect. If you have access to IIS manager on server, go to error pages and configure 404 error.

    Make sure you enable custom error instead of showing error details (file not found error message)

    Sunday, June 9, 2013 8:50 AM
  • User281315223 posted

    Try adding the following code to your web.config, which should handle the appropriate redirect (even in the case of non-existing URLs) : 

    <system.webServer>
        <httpErrors existingResponse="Replace" errorMode="Custom">
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" prefixLanguageFilePath="" path="/YourRedirectLocation.aspx" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>

    (Related Stack Overflow)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 9, 2013 9:04 AM
  • User476696664 posted

    It's on a shared server so we aren't capable of achieving this since we can't access any modules on the server..

    Monday, June 10, 2013 6:07 PM
  • User476696664 posted

    Tested this and it doesn't work unforunately :( 

    Monday, June 10, 2013 6:07 PM
  • User-801004448 posted

    It's on a shared server so we aren't capable of achieving this since we can't access any modules on the server..

    Do you have IIS on your local computer? Create a website and configure 404 error, test on your local computer, then copy 404 configuration in web.config file to shared host server.

    You can also ask your host to configure 404 error for you. It can be done quickly.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 12, 2013 11:03 PM