IIS URL rewrite path to querystring - asp.net

Need some help specifying rewrite rule for:
http://example.com/page/my-unique-title
to
http://example.com/page?id=my-unique-title
Note it is web forms app and I am using friendlyurls. Any help much appreciated.

Try this:
<rule name="myrule" stopProcessing="true">
<match url="page/(.*)" />
<action type="Rewrite" url="page?id={R:1}" />
</rule>

Related

Website URL mapping from ASP.Net URL to MVC URL to redirect

We would like to redirect users from below URL
http://mywebsite.com/Account.asp?Number=25191108
To
http://anotherwebsite.com/Account/25191108
Please let me know if we can do it by config at IIS level or in web.config
You can use URL Rewrite module in IIS to achieve this. You can install it from here.
Add the following rule in your web.config file under "system.webServer" tag.
Let me know if it breaks or if you have any questions around this.
<rewrite>
<rules>
<clear />
<rule name="sample2" stopProcessing="true">
<match url="(.*).asp(.*)Number=(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="http://anotherWebsite.com/{R:1}/{R:3}" redirectType="Temporary" />
</rule>
</rules>
</rewrite>

I want to optimize my URL for SEO purpose. Using Umbraco ASP.NET

<rule name="blog categories" stopProcessing="true">
<match url="/?blog/categories/([^/]+)/" />
<action type="Redirect" url="/blog/cat={R:1}" />
</rule>
This is the code in web.config might be helpful to you.
my url : capcom/?page=2
I want to remove '?' from the url or '/'.
To use urls like .../page/2 instead of ...?page=2 you can add this rule to the rewrite section of your web.config:
<rule name="pagination" stopProcessing="true">
<match url="(.+)/page/([0-9]+)$" />
<action url="{R:1}?page={R:2}" type="Rewrite" />
</rule>
I suggest you just put a canonical url in your , which doesn't have the query string on it. That might look like:
<link rel="canonical" href="#Model.Current.Url">

Create a rule with Service.Transfer() Behaviour IIS Rewriting Module

Is it possible to create a rule that has a behaviour similar to the Service.Transfer from ASP ?
Using IIS7 Rewriting Module you can use a Rewrite Action.
This keeps the original URL but rewrites the path which your application will see and process in a similar way to Server.Transfer.
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.aspx?id={R:1}&title={R:2}" />
</rule>
</rules>
</rewrite>
Have a look at the rules overview.
This essentially is the same as Context.RewritePath.

Why is this rewrite rule not working?

I am using ASP.NET URL Rewrite module and wrote this rule :
<rewrite>
<rules>
<rule name="test">
<match url="http://localhost/ElWazefa/User/Ahmed/ahmed.aspx"/>
<action type="Rewrite" url="http://localhost/ElWazefa/ahmed.aspx"/>
</rule>
</rules>
</rewrite>
But it doesn't work.
using asp.net 3.5 and XML IntelliSense for URL Rewrite 2.0
Thanks in advance.
the code syntax seems to be correct
try to check your URLs for typos or leave the port/host out of the URL like that:
"/ElWazefa/User/Ahmed/ahmed.aspx"
I think your URLs can't include the protocol/host/port portion. Try:
<rewrite>
<rules>
<rule name="test">
<match url="/ElWazefa/User/Ahmed/ahmed.aspx"/>
<action type="Rewrite" url="/ElWazefa/ahmed.aspx"/>
</rule>
</rules>
</rewrite>

Redirect from Default.aspx to root using IIS7

When request comes to www.example.com/default.aspx, I want it to 301 to www.example.com. How to do that?
PS - I tried many rules but nothing seems to work. Thanks.
Have you tried using URL Rewrite with the following rule:
<rule name="Default Document" stopProcessing="true">
<match url="(.*)default.aspx" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>

Resources