url重定向或者重写

有四种方式:1.urlMappings,返回200状态码

 <system.web>

 <urlMappings >

      <add url="~/others.aspx?secondmenu=10308&type=singlepage" mappedUrl="~/product/website/1101_2" />

    </urlMappings>

  </system.web>

 2.rewrite 返回301

<configuration>

    <system.webServer>

        <rewrite>

            <rules>

                <rule name="Redirect t and c" stopProcessing="true">

                    <match url="^terms_conditions$" />

                    <action type="Redirect" url="/TermsAndConditions" />

                </rule>

            </rules>

        </rewrite>

    </system.webServer>

</configuration>

 3.globax.cs中处理 返回301

 private void AddDic()

        {

            dic301List.Add("/others.aspx?secondmenu=10308&type=singlepage", "/product/website/1101_2");

        }





        protected void Application_BeginRequest(object sender, EventArgs e)

        {

            var url = Request.Url.ToString().ToLower();

            if (dic301List.ContainsKey(url))

            {

                Response.RedirectPermanent(dic301List[url], true);

            }

        }

 4.mvc路由 返回301

routes.MapRoute(

        name: "News old route",

        url: "web/news/Default.aspx",

        defaults: new { controller = "Redirect", action = "News" }

    );



public class RedirectController : Controller

{



    public ActionResult News()

    {



        // your code



        return RedirectPermanent("/News");

    }

}

 

你可能感兴趣的:(url)