网址重写问题 [英] How to do url rewrite problem
本文介绍了网址重写问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi to all
I am facing problem to rewrite the url for more then 3 pages
iam using urlrewrite http module
<httpModules><add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/></httpModules>
<rewriter>
<rewrite url="~/(.+)-(.+)_aspx" to="~/ViewVideos.aspx?mID=$2"/>
<rewrite url="~/(.+)-(.+)-aspx" to="~/ViewGalery.aspx?GID=$2"/>
<rewrite url="~/(.+)-(.+).aspx" to="~/ViewPage.aspx?TitleID=$2"/>
</rewriter>
the below code i am using inside page
public static string GenerateURL(object Title, object strId)
{
string strTitle = Title.ToString();
#region Generate SEO Friendly URL based on Title
//Trim Start and End Spaces.
strTitle = strTitle.Trim();
//Trim "-" Hyphen
strTitle = strTitle.Trim('-');
strTitle = strTitle.ToLower();
char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();
strTitle = strTitle.Replace("c#", "C-Sharp");
strTitle = strTitle.Replace("vb.net", "VB-Net");
strTitle = strTitle.Replace("asp.net", "Asp-Net");
//Replace . with - hyphen
strTitle = strTitle.Replace(".", "-");
//Replace Special-Characters
for (int i = 0; i < chars.Length; i++)
{
string strChar = chars.GetValue(i).ToString();
if (strTitle.Contains(strChar))
{
strTitle = strTitle.Replace(strChar, string.Empty);
}
}
//Replace all spaces with one "-" hyphen
strTitle = strTitle.Replace(" ", "-");
//Replace multiple "-" hyphen with single "-" hyphen.
strTitle = strTitle.Replace("--", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("-----", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("--", "-");
//Run the code again...
//Trim Start and End Spaces.
strTitle = strTitle.Trim();
//Trim "-" Hyphen
strTitle = strTitle.Trim('-');
#endregion
//Append ID at the end of SEO Friendly URL
strTitle = strTitle + "-" + strId + ".aspx";
return strTitle;
}
now i want to rewrite the url for sub folder pages
i have the sub floder/En
/En i have the Eviewpage and also Default page
now i want to Rewrite the url for Default page links to Eviewpage
these two pages are present in side sub floder
please help me to find the sollution.
推荐答案
2" ">> 跨度> < 重写 URL 〜/(.+)-(.+)- aspx" 至 =" 〜/ViewGalery.aspx?GID =
2"/> <rewrite url="~/(.+)-(.+)-aspx" to="~/ViewGalery.aspx?GID=
2" > < 重写 URL 〜/(.+)-(.+).aspx" 至 =" 〜/ViewPage.aspx?TitleID =
2"/> <rewrite url="~/(.+)-(.+).aspx" to="~/ViewPage.aspx?TitleID=
2" > < /rewriter > 我在内部页面使用的以下代码 公共静态字符串GenerateURL(object Title,object strId) { 字符串strTitle = Title.ToString(); #region根据标题生成SEO友好的URL //修剪开始和结束空间. strTitle = strTitle.Trim(); //修剪-"连字号 strTitle = strTitle.Trim('-'); strTitle = strTitle.ToLower(); char [] chars = @"
2"/> </rewriter> the below code i am using inside page public static string GenerateURL(object Title, object strId) { string strTitle = Title.ToString(); #region Generate SEO Friendly URL based on Title //Trim Start and End Spaces. strTitle = strTitle.Trim(); //Trim "-" Hyphen strTitle = strTitle.Trim('-'); strTitle = strTitle.ToLower(); char[] chars = @"
这篇关于网址重写问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文