This response contains links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.Microsoft does not control these sites and
has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.There are inherent dangers in the use of any software
found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
suryaacd
Member
108 Points
286 Posts
How to redirect url using UrlRewriter.Net
May 18, 2012 06:51 PM|LINK
Hi,
I am pretty new to URL Rewriting concept. In my project I need to display the url
say for eg. localhost/default.aspx as localhost/en/default.
Also, if the url is like localhost/en/default.aspx, it should redirect as localhost/en/default.
If the language selected is Chinese, the url will be localhost/zh-CHS/default-zh.aspx .
It should be rewritten as localhost/zh-CHS/default-zh.
Also, if url in chinese is localhost/about-zh.aspx it should be displayed as localhost/zh-CHS/about-zh.
The default language is English.
I am trying to achieve this with UrlRewriter.Net (Intelligencia.UrlRewriter)
Can anyone please tell how to write the rules in the web.config to achieve this?
I am doing this project in .Net 4.0 .
Please help.
Thanks,
Surya.
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: How to redirect url using UrlRewriter.Net
May 21, 2012 11:25 AM|LINK
Hi
MSDN is your friends
http://msdn.microsoft.com/en-us/library/ms972974.aspx#urlrewriting_topic7
And
http://www.codeproject.com/Articles/2538/URL-Rewriting-with-ASP-NET
Also you need some regular expression knowledge:
http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet
Hope it helpful.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
suryaacd
Member
108 Points
286 Posts
Re: How to redirect url using UrlRewriter.Net
May 22, 2012 04:19 PM|LINK
Hi,
Can anyone please help. I don't know how to write rules in web.config to achieve extensionless urls
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: How to redirect url using UrlRewriter.Net
May 23, 2012 07:46 AM|LINK
Hi
Have you readed the link I gave you?
First you need to download the URLRewriter.
http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi
Then add code like this in your web.config
<configuration> <configSections> <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/> </configSections> <RewriterConfig> <Rules> <RewriterRule> <LookFor>/ShowQueryString_post/(\d{4})/(\d{2})/(\d{2})/(\d{1})</LookFor> <SendTo>~/ShowQueryString_post.aspx?Year=$1&Month=$2&Day=$3&id=$4</SendTo> </RewriterRule> </Rules> </RewriterConfig> <system.web>In my code LookFor is a regular expression(That's why I said you need to know the regular expression).
So when I input [domainname]/ShowQueryString_post/2012/05/02/1
It will convert to [domainname]/ShowQueryString_post.aspx?Year=2012&Month=05&Day=02id=1
Hope you read those link first, and then post threads with some specific problem.
Hope it helpful.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
suryaacd
Member
108 Points
286 Posts
Re: How to redirect url using UrlRewriter.Net
May 23, 2012 08:45 AM|LINK
Hi,
I am trying with urlrewriter.net
For that I added a reference for Intelligencia.UrlRewriter dll in my project.
Then in web.config added these sections.
<configSections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</httpModules>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>
</system.webServer>
<rewriter>
</rewriter>
I don't know how to write the rules in rewrite section.
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: How to redirect url using UrlRewriter.Net
May 25, 2012 08:47 AM|LINK
Hi
You can refer to this link:http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
<rewrite url="~/products/(.+).aspx" to="~/products.aspx?category=$1" />
Can you understand this line?
(.+) this is a Regulary expression.
I had post the link before.
This line mean when you get ~/products/[anypagename].aspx it will convert to ~/products.aspx?category=[anypagename]
Here is some tutorial.
http://dotnetguts.blogspot.com/2008/07/url-rewriting-with-urlrewriternet.html
I think you just can't understand how does the Regular expression work.
I suggest you download this open source URL write module, and try to understand it first.
http://urlrewriter.net/index.php/download
This response contains links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework