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
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:
Then add a rewrite rule to use the mappings you just defined:
In your case you’ll want to use the
Redirect
action rather thanRewrite
.The module provides a lot of other configuration options.
On asp.net webforms set a page i.e. Redirect.aspx to redirect all the Error of type 400:
then on the page see the Url it cames from by:
then handle accordingly