skip to Main Content

The Seo Company ask for making redirect each 404 bad request to specific url.
I asked for redirect an error 400 (Bad request) to special page.

I can do it in the web.config file, but the requirement is each url to special page
for example
https://stackoverflow.com/questions/askhttps://stackoverflow.com/questions/ask =>(301) https://stackoverflow.com/questions/ask
https://stackoverflow.com/questionshttps://stackoverflow.com/questions => (301) https://stackoverflow.com/questions

Is it possible?
My application is ASP.NET (Not MVC) on IIS SERVER

Thanks

2

Answers


  1. Caveat:

    You say this is “ASP.NET (not MVC)”. I’m going to assume this means you’re using WebForms rather than ASP.NET Core. The following advice can be used in both cases, but in case of ASP.NET Core only if you’re hosting with IIS.

    Answer:

    You’re looking for IIS URL Rewrite, a module that can be installed in IIS then configured via your web.config. One feature this provides is rewrite maps which are essentially a list of from and to URL mappings where a request for the former will cause a redirect to the latter. The documentation for URL Rewrite maps is here, and here’s an example from the documentation:

    Define your mappings:

    <rewrite>
        <rewriteMaps>
            <rewriteMap name="StaticRewrites" defaultValue="">
                <add key="/article1" value="/article.aspx?id=1&amp;title=some-title" />
                <add key="/some-title" value="/article.aspx?id=1&amp;title=some-title" />
                <add key="/post/some-title.html" value="/article.aspx?id=1&amp;title=some-title" />
            </rewriteMap>
        </rewriteMaps>
    </rewrite>
    

    Then add a rewrite rule to use the mappings you just defined:

    <rules>
        <rule name="Rewrite Rule">
            <match url=".*" />
            <conditions>
                <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
            </conditions>
            <action type="Rewrite" url="{C:1}" />
        </rule>
    </rules>
    

    In your case you’ll want to use the Redirect action rather than Rewrite.

    The module provides a lot of other configuration options.

    Login or Signup to reply.
  2. On asp.net webforms set a page i.e. Redirect.aspx to redirect all the Error of type 400:

    <configuration>
     <system.web>
       <customErrors defaultRedirect="Error.htm"
                     mode="RemoteOnly">
         <error statusCode="400"
                redirect="Redirect.aspx"/>
       </customErrors>
     </system.web>
    

    then on the page see the Url it cames from by:

    Request.UrlReferrer
    

    then handle accordingly

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search