Sitecore not respecting II7 URL Rewrite module - iis

I am trying to get the IIS7 URL Rewrite module working with Sitecore. I imported some rules and successfully tested them, but when I attempt to go to a URL I've setup a redirect for I get the Sitecore 404 page instead. So it's as if Sitecore is intercepting the page request before the URL Rewrite module has a chance to.
Sample rule:
<rule name="Imported Rule 1">
<match url="/pastsub(.*)" ignoreCase="false" />
<action type="Redirect" url="http://www.domain.net" redirectType="Found" />
</rule>
Any ideas on how to fix this?

Adding stopProcessing="true" to the rule will probably solve your problem:
<rule name="Imported Rule 1" stopProcessing="true">
<match url="/pastsub(.*)" ignoreCase="false" />
<action type="Redirect" url="http://www.domain.net" redirectType="Found" />
</rule>

Related

URL Rewrite rule for a specific domain

URL Rewrite rule for a specific domain
if url is https and have this domain only
https://myServer/SomeApplication/
Redirect it to
https://myServer.mycompany.com/SomeApplication/
Added below didn't work in iis 10, windows server 2019
<rule name="httpsRedirect2" enabled="true" stopProcessing="true">
<match url="^myServer/(.*)" ignoreCase="true"/>
<action type="Redirect" url="https://myServer.mycompany.com/SomeApplication/" appendQueryString="false" />
</rule>
Can someone explain what I've done wrong?
The Rule pattern only can get the URL string as an input, does not include the query string, thus it will not work properly.
Here is an official explanation of how certain parts of the URL string can be accessed from a rewrite rule.
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#accessing-url-parts-from-a-rewrite-rule
We can match the hostname in the Rule Condition section then apply the Rule Action.
<rule name="Myrule2" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" />
</conditions>
<action type="Redirect" url="https://vabqia969vm/" />
</rule>
</rules>
</rewrite>
Feel free to let me know if the problem still exists.

IIS rewrite rule not triggered when file-name plus extension is in the url

I am struggling getting an IIS rewrite rule working.
The old urls look like:
https://wwww.testserver.com/package.aspx?TrackingNumber=number
The new web app is expecting the urls in this format:
https://wwww.testserver.com/package/number
Currently I have the following rule setup, which is not working.
<rule name="Rewrite to new Package site" stopProcessing="true">
<match url="^package\.aspx\?TrackingNumber=([_0-9a-z-]+)" />
<action type="Redirect" url="https://www.testserver.com/package/{R:1}" logRewrittenUrl="true" />
</rule>
The interesting part is, if I remove package.aspx\? from the rule, urls like these https://wwww.testserver.com/oldwebsite/TrackingNumber=number are getting matched.
In my test calls I replaced package.aspx with package.html and these urls are not getting matched as well. It looks like IIS ignores urls with filenames in the url.
You could use below url rewrite rule to redirect https://wwww.testserver.com/package.aspx?TrackingNumber=number to https://wwww.testserver.com/package/number:
<rule name="test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" pattern="package(.aspx)" />
<add input="{QUERY_STRING}" pattern="TrackingNumber=(.*)" />
</conditions>
<action type="Redirect" url="http://localhost:2568/package/{C:1}" appendQueryString="false" />
</rule>
Note: You could modify hostname as per your requirement.
Regards,
Jalpa

IIS URL Rewrite rule to replace part of the URL

I am new to the IIS Rewrite rule and trying to create a rule to replace part of url
e.g.www.abc.com/assets/global/xyz.jpg
should redirect to www.abc.com**/en/globalassets/**assets/global/xyz.jpg
I fiddle around with the following rule but no success
<rule name="url replace">
<match url="^(.com/assets/global/)" />
<action type="Rewrite" url=".com/en/globalassets/assets/global/{R:2}" />
</rule>
According to your description, I have tested on my side , you could use urlrewite rule as below:
<rule name="rule1" enabled="true" stopProcessing="true">
<match url="assets/global/(.*)" />
<conditions>
<add input="{REQUEST_URI}" pattern="en/globalassets" negate="true" />
</conditions>
<action type="Redirect" url="http://{domain}/en/globalassets/assets/global/{R:1}" />
</rule>
Firstly, we couldn't add value like **.com in match url, because this part could only catch path of the url.
You could see this is a url structure:
http(s)://httphost/path?querystring.
You could only get it in conditions tag but not pattern.
Then you should add condition to check the request URL match "en/globalassets" or not to avoid running redirect rule once and once again.

URL Alias in IIS 8.5 Using URL Rewrite Module

I need to create easy to remember URL's that redirect to long and hard to remember paths for a large number of applications.
i.e.
subdomain.domain.edu/shortname
redirects to
https://www.subdomain.domain.edu/mainApplication/subfolder/page
I'm using the URL Rewrite module in IIS 8.5, but I keep getting a 404 when I browse to the short alias. I know the rewrite module is working as I use it to handle rewriting HTTP to HTTPS and to add WWW to a URL.
My rewrite rule looks like:
<rewrite>
<rules>
<rule name="Easy to remember shortcut" stopProcessing="true">
<match url=".*subdomain.domain.edu/shortname" />
<conditions>
<add input="{URL}" pattern=".*/shortname" />
</conditions>
<action type="Redirect" url="https://www.subdomain.domain.edu/mainApplication/subfolder/page.aspx" />
</rule>
</rules>
</rewrite>
Of course this returns a 404. Any ideas?
Forgive me if there is already an answer to this in another post, however, I've read through and tried over 30 posts on the URL rewrite module and have not yet found the solution for actually creating an alias.
Url rewrite match condition won't be able to see your domain i.e. if the URL is https://www.subdomain.domain.edu/shortname the match part can only see shortname (anything after domainname/).
To validate the host we need to add in the conditions clause. So your rule will be something like below
<rule name="shortnameURL" enabled="true" stopProcessing="true">
<match url="shortname" />
<action type="Redirect" url="mainApplication/subfolder/page" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*subdomain.domain.edu" />
</conditions>
</rule>
Also it should be ok if you add the entire URL here
<action type="Redirect" url="mainApplication/subfolder/page" /> as below
<action type="Redirect" url="https://www.subdomain.domain.edu/mainApplication/subfolder/page" />

Simple IIS url rewrite not working

I am trying to hide a subdirectory where I installed a framework. While this works like a charm in .htaccess, I am getting stuck with IIS rules. Basically I want to go from
http://www.mysite.com/CI/client-tracking to
http://www.mysite.com/client-tracking
I am using this rule
<rule name="Redirect to Codeigniter" stopProcessing="true">
<match url="^client-tracking$" ignoreCase="false" />
<action type="Rewrite" url="/CI/client-tracking" />
</rule>
LE: I am not in need of a redirect, I need to rewrite the URL and eliminate the \CI directory from it, so the user and search engines see a nice link.
Did you try removing the leading "/" on the re-written url
<rule name="Redirect to Codeigniter" stopProcessing="true">
<match url="^client-tracking$" ignoreCase="false" />
<action type="Rewrite" url="CI/client-tracking" />
</rule>

Resources