I want to use IIS Rewrite to change /blog.aspx?Page=2 to /blog?Page=2 but as its the address is in a DataPager, its not so simple. TO get round this, I've come up with the following IIS rewrite rule.
<outboundRules>
<rule name="BlogArticlesOutbound" stopProcessing="true">
<match filterByTags="A" pattern="^/blog.aspx\?page=([0-9]+)" />
<action type="Rewrite" value="/blog?page={R1}" />
</rule>
</outboundRules>
However, the output is missing the page number, what do I need to do to change it to get it to work? My style sheet seems to also disappear from the page when i use the rule.
Your back-reference syntax is a tiny bit wrong. You should use it as {R:1}.
<outboundRules>
<rule name="BlogArticlesOutbound" stopProcessing="true">
<match filterByTags="A" pattern="^/blog.aspx\?page=([0-9]+)" />
<action type="Rewrite" value="/blog?page={R:1}" />
</rule>
</outboundRules>
Related
I just need to create a rule in my web config file to rewrite all URLs to given into rule
ex:
url/services/presentations-evenementielles to
url/Services/Presentations-Evenementielles
This is all made for SEO purposes to avoid duplicates.
<rule name="ProductionRule2" stopProcessing="true" patternSyntax="ExactMatch" >
<match url="^/productions/xyz" ignoreCase="true" />
<action type="Redirect" url="Productions/XYZ" redirectType="Permanent"/>
</rule>
Above code its gives me infinite loop error.
There was some mistakes with your rule
1.You were trying to use "^" in an exact match rule. Please set it to regular expression
2.You are trying to use "/" in match url. The match url part of domain/productions/xyz is
productions/xyz instead of /production/xyz.
3.You are enabling ignore case when you redirect URL to itself.
So please try to modify the rule like this
<rule name="ProductionRule2" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^productions/xyz" ignoreCase="false" />
<action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
</rule>
Update:
Please modify the rule like this
<rule name="ProductionRule2" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^Productions/XYZ" ignoreCase="false" negate="true" />
<action type="Redirect" url="Productions/XYZ" redirectType="Permanent" />
<conditions>
<add input="{ToLower:{URL}}" pattern="/productions/xyz" />
</conditions>
</rule>
And this is working on my side
Please remember to clean browser cache when you test the rule.And the URL should be prODuctions/Xyz instead of prODuction/Xyz.
The input url is http://www.mywebsite.com/en-us/lookingtobuy/propertiesforsale.aspx?ppid=MD19863 and I need the URL to redirst to http://www.mywebsite.com/lookingtobuy/propertiesforsale.aspx?ppid=MD19863
So I need to remove the en-us/
everything following the ?ppid/ is a variable and so any rule written would need to allow for that to match what ever the input is
This rule should work :
<rule name="remove en-US">
<match url="^/en-US/(.*)" />
<action type="Rewrite"
url="http://{HTTP_HOST}/{R:1}" />
</rule>
And if you need to allow other culture
<rule name="remove culture">
<match url="^/(\w{2}-\w{2})/(.*)" />
<action type="Rewrite"
url="http://{HTTP_HOST}/{R:2}" />
</rule>
{R:x} is a back reference to the rule pattern. For the second rule
{R:0} will be /en-us/lookingtobuy/propertiesforsale.aspx?ppid=MD19863
{R:1} will be en-us
{R:2} will be lookingtobuy/propertiesforsale.aspx?ppid=MD19863
I am having an issue trying to get the rewrite working in IIS7 web.config.
I need URLs like /err/interaccess to be rewritten to /err/404new.asp (not a redirect,as I don't want to expose the file.
I tried the following and it only works if I use /interaccess but not /err/interaccess
<rule name="Rewrite Interaccess Error" enabled="true" stopProcessing="true">
<match url="^tinteraccess$" />
<action type="Rewrite" url="/err/404new.asp" />
</rule>
Any idea on why? I tried to find documentation on this and could not find anything regarding this usage.
The magic is in the regular expression of the <match> tag. To make it match your exact URL you would use:
<rule name="Rewrite Interaccess Error" enabled="true" stopProcessing="true">
<match url="^err/interaccess$" />
<action type="Rewrite" url="/err/404new.asp" />
</rule>
If you would want to match everything under /err/ you would use:
<rule name="Rewrite Interaccess Error" enabled="true" stopProcessing="true">
<match url="^err/" />
<action type="Rewrite" url="/err/404new.asp" />
</rule>
This is all very well documented, e.g.: http://www.iis.net/downloads/microsoft/url-rewrite (see Related Learning)
I'm trying to use the rewrite rule from the HTML 5 Boilerplate project to make circumventing browser cache (aka cache busting):
<rewrite>
<rules>
<rule name="Cachebusting">
<match url="^(.+)\.\d+(\.(js|css|png|jpg|gif)$)" />
<action type="Rewrite" url="{R:1}{R:2}" />
</rule>
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
</conditions>
<action type="Redirect" url="http://chewsy.com{PATH_INFO}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
If i try to access my css with /css/all.123456.css, it fails to find the file with the error reporting that it's looking for /css/all.123456.css (no rewrite). I've tried commenting out the "Remove WWW" rule to see if that was a conflict, but same behavior.
Any ideas why this rule isn't being applied and rewriting the URLs?
Update: I'm using these settings for my web server in VS2010:
<match url="^(.+)\.\d+\.(js|css|png|jpg|gif)$" />
<action type="Rewrite" url="{R:1}.{R:2}" />
I pressume you want to get /css/all.css, if not, post the desired result...
EDIT: VS internal development server (Cassini) doesn't support IIS URL Rewriting Module, you would have to use IIS (Express) for that, or some third party component (http://urlrewriter.net/)...
I have a site that currently uses the .aspx extension on its pages. It's getting a Joomla conversion and the .aspx extension will not work anymore. I need it so that if someone enters the .aspx extension, it will just get removed the URL so none of the SEO on the current site breaks.
For example, I need
www.arrc.com.php5-17.websitetestlink.com/services/managed-services.aspx
to be rewritten/redirected to
www.arrc.com.php5-17.websitetestlink.com/services/managed-services
This is what I have in my web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Migrate to PHP">
<match url="^([_0-9a-z-]+)\.aspx" />
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
<rule name="Rewrite .aspx">
<match url="^([_0-9a-z-]+)/?([_0-9a-z-]+)\.aspx" />
<action type="Redirect" redirectType="Permanent" url="{R:1}/{R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The first URL match is for any URLs that have a URL like services.aspx instead of services/managed-services.aspx
Whenever I go to www.arrc.com.php5-17.websitetestlink.com/services/managed-services.aspx it gives me an internal server error, but www.arrc.com.php5-17.websitetestlink.com/services.aspx rewrites correctly. What can I do to fix this?
They are greedy, switch the order.
<rule name="Rewrite .aspx">
<match url="^([_0-9a-z-]+)/?([_0-9a-z-]+)\.aspx" />
<action type="Redirect" redirectType="Permanent" url="{R:1}/{R:2}" />
</rule>
<rule name="Migrate to PHP">
<match url="^([_0-9a-z-]+)\.aspx" />
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
Two potential issues:
I think for rewriting, it's going to hit them in order, which means the first rule is going to always kick off. Try switching the order of the rule.
The dash should work correctly in [_0-9a-z-], but try escaping the dash.