urls.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<urls>
<rewrite name="indexlogo"
path="/logo_{0}/index.html"
pattern = "/logo_(\d+)?/index.html"
page="/indexlogo.aspx"
querystring="brandpid=$1" />
</urls>
httpmodule类:
private void ReUrl_BeginRequest(object sender, EventArgs e)
{ HttpContext context = ((HttpApplication)sender).Context;
//string forumPath = "/0377autocarweb/";//xfly.web
string forumPath = "/";//xfly.web
string requestPath = context.Request.Path.ToLower(); if (requestPath.StartsWith(forumPath) && requestPath.IndexOf("/selectcar/") < 0 && requestPath.IndexOf("/images/") < 0 && requestPath.IndexOf("/tools/") < 0 && requestPath.IndexOf("test.aspx") < 0)
{
if (requestPath.EndsWith("/") && (requestPath.IndexOf(".html") < 0))
{
requestPath = requestPath + "index.html";
}
foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls)
{ if (Regex.IsMatch(requestPath, url.Pattern, Utility.GetRegexCompiledOptions() | RegexOptions.IgnoreCase))
{ string newUrl = Regex.Replace(requestPath.Substring(forumPath.Length - 1), url.Pattern, url.QueryString, Utility.GetRegexCompiledOptions() | RegexOptions.IgnoreCase);
context.RewritePath(forumPath+url.Page, string.Empty, newUrl);
return;
} }
} }
我在本机测试成功http://localhost:52857/0377AutoCarWeb/logo_1/ ->成功
放到服务器上测试http://127.0.0.1/logo_1/ ->不成功。提示“无法找到该页” HTTP 错误 404 - 文件或目录未找到。
<?xml version="1.0" encoding="utf-8" ?>
<urls>
<rewrite name="indexlogo"
path="/logo_{0}/index.html"
pattern = "/logo_(\d+)?/index.html"
page="/indexlogo.aspx"
querystring="brandpid=$1" />
</urls>
httpmodule类:
private void ReUrl_BeginRequest(object sender, EventArgs e)
{ HttpContext context = ((HttpApplication)sender).Context;
//string forumPath = "/0377autocarweb/";//xfly.web
string forumPath = "/";//xfly.web
string requestPath = context.Request.Path.ToLower(); if (requestPath.StartsWith(forumPath) && requestPath.IndexOf("/selectcar/") < 0 && requestPath.IndexOf("/images/") < 0 && requestPath.IndexOf("/tools/") < 0 && requestPath.IndexOf("test.aspx") < 0)
{
if (requestPath.EndsWith("/") && (requestPath.IndexOf(".html") < 0))
{
requestPath = requestPath + "index.html";
}
foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls)
{ if (Regex.IsMatch(requestPath, url.Pattern, Utility.GetRegexCompiledOptions() | RegexOptions.IgnoreCase))
{ string newUrl = Regex.Replace(requestPath.Substring(forumPath.Length - 1), url.Pattern, url.QueryString, Utility.GetRegexCompiledOptions() | RegexOptions.IgnoreCase);
context.RewritePath(forumPath+url.Page, string.Empty, newUrl);
return;
} }
} }
我在本机测试成功http://localhost:52857/0377AutoCarWeb/logo_1/ ->成功
放到服务器上测试http://127.0.0.1/logo_1/ ->不成功。提示“无法找到该页” HTTP 错误 404 - 文件或目录未找到。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货