asp.net - Blocking invalid URL and redirect to homepage in IIS -


currently using web hosting service provided company. uses iis 7/iis 8 , allows customers modify web.config according needs.

suppose have set 2 valid url:

  1. http://www.example.com
  2. http://dev.example.com

now, when try access http://abc.example.com, http error 403.14 - forbidden returned; , if try access http://www.example.com/abc, http error 404.0 - not found returned.

how can configure web.config such users redirected http://www.example.com when trying access invalid url?

i have tried use snippet provided company without success:

<?xml version="1.0" encoding="utf-8"?> <configuration>     <system.webserver>         <rewrite>             <rules>                 <rule name="canonical host name" stopprocessing="true">                   <match url="(.*)" />                   <conditions>                     <add input="{http_host}" pattern="^example\.com$" />                   </conditions>                   <action type="redirect" url="http://www.example.com/{r:1}" redirecttype="permanent" />                 </rule>              </rules>         </rewrite>     </system.webserver> </configuration> 

in system.web in webconfig tag add tag

<customerrors mode="on" defaultredirect="~/home/index">   </customerrors> 

this redirect home page whenever error occured can more specific redirection adding in customerrors tag

<error statuscode="401" redirect="/error/otherpage"/> 

this indicate page redirected when 401 error occurs


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -