码迷,mamicode.com
首页 > Web开发 > 详细

url重定向或者重写

时间:2015-06-17 09:20:17      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

有四种方式: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重定向或者重写

标签:

原文地址:http://www.cnblogs.com/maomao999/p/4582334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!