IIS Url rewrites with Sitecore - url-rewriting

I'm using the IIS URL rewrite add-on in my Sitecore v7.2 website to handle redirects.
I've setup the Rewrites on the website node in IIS and not on the top level IIS server.
These are simple redirects such as appending a slash in certain situations
<rule name="CA Redirect" stopProcessing="true">
<match url="^ca$" />
<action type="Rewrite" url="{R:0}/" />
</rule>
I'm finding that unless I add the path e.g. "/ca" to the IgnoreUrlPrefixes in Sitecore IIS will not process the redirect, and it appears that Sitecore is handling the request before the URL rewrite rule.
Has anyone else come across this issue? Should the rules be added at the top level rather than the website level?

We're using redirects at website level and it works without problems. IIS is redirecting before Sitecore handles the request.
Doing it at site level is generating this in the web.config
<rewrite>
<rules>
<rule name="Web closed" enabled="true" stopProcessing="true" patternSyntax="Wildcard">
<match url="*" />
<action type="Rewrite" url="/holdingpage.html" logRewrittenUrl="true" redirectType="Temporary" />
</rule>
</rules>
</rewrite>

Related

How to write IIS rewrite rule to redirect request to different server?

I have my main website running at a hosting company with IIS 7.5 at http://example.com
I'm setting up a WordPress blog at the same hosting company on a Linux, Apache, PHP machine.
When a user types in "http://example.com/blog" I want to redirect the request to the WordPress site.
To the end user they wouldn't know the blog content is being served up from a different server.
What is the specific IIS rewrite rule needed to do this?
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.mysite1.com$" />
</conditions>
<action type="Redirect" url="www.mysite2.com" />
</rule>
</rules>
</rewrite>

Url Rewrite not working in umbraco 7

I added the below code to redirect in urlrewrite.config
<add name="regx" virtualUrl="~/about/(.*)/2016/(.*)/12/"
redirect="Application" destinationUrl="~/about/$1"
redirectMode="Permanent" />
And i added the below code to rewrite in web.config
<rewrite>
<rules>
<rule name="regx">
<match url="^/about/news/2016/(.*)/12/" />
<action type="Rewrite" url="about/news/2016/{R:1}/12" />
</rule>
</rules>
</rewrite>
This above code change my url from "//192.168.18.159:8741/about/news/2016/feb/12" to "//192.168.18.159:8741/about/news/". It get redirect to news page i am not able to get redirect to exact url as "//192.168.18.159:8741/about/news/2016/feb/12"
i am not able to get rewrite and redirect i added the UrlRewritingNet.UrlRewriter.dll and used correctly in web config.
i need to change my url from "//192.168.18.159:8741/about/news/2016/feb/12" to "//192.168.18.159:8741/about/news/feb/"
Please give some solution as soon as possible. Thanks in advance

How to configure web.config to load resources form external server

I'm developing a web application in Visual Studio 2013 and am getting my data from an external server. For this reason I disable the web securtiy in my browser and define absolute URLs in my application. Now whenever I'm deploying the applicaiton, I have to adopt the URLs (which of course get's forgotten the first time) and also I have to explain the setup to evey person new in the porject.
After getting a bit fimilar with the web.config file, I tried to setup some rules, to rewirte this urls to the data webserver, but failed.
All my relative urls start with the same identifyer, and should be mapped to an external server. This is what I have so far:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite calls to rest.oms to the actuall webserver">
<match url="^/IDENTFIER/([_0-9a-z-]+)" />
<action type="Rewrite" url="http://EXTERNAL_SERVER/IDENTFIER/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
However, it is not working so far. Can somebody help me please.
Best Regards,
Stefan
It is possible to rewrite from external url, if you have ARR module.
1) You need to install ARR module for your IIS
2) In IIS manager you should enable reverse proxy
2.1) On server node click "Application Request Routing Cache"
2.2) Click "Server proxy settings" and click "Enable proxy", then "Apply"
3) Slightly fix your rewrite rule regexp (remove starting slash):
<rule name="Rewrite calls to rest.oms to the actuall webserver">
<match url="^IDENTFIER/([_0-9a-z-]+)" />
<action type="Rewrite" url="http://EXTERNAL_SERVER/IDENTFIER/{R:1}" />
</rule>
Then your rule should work.

Rewriting Subdomains in IIS

I'm having some trouble rewriting some things in IIS
Here is what I'm trying to achieve.
We have a bunch of clients that all need a subdomain. For example
http://clientA.mysite.com needs to be rewritten to http://mysite.com/clientArea/?clientID=1234
Then all content needs to be rewrriten to http://mysite.com/clientArea/XXX
so for example if someone requests http://clientA.mysite.com/example.css , that should be rewritten to http://mysite.com/clientArea/example.css
I cannot for the life of me get this working right.
I think I have to to do this in 2 rules. I think I have the first rule working kindof (page looks whack because it can't get the JS files or CSS files to make it look right)
Here is my first rule to rewrite http://clientA.mysite.com to http://mysite.com/clientArea/?clientID=1234
<rule name="Rewrite Subdomain" stopProcessing="true">
<match url="()" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)clientA\.mysite\.com$" />
</conditions>
<action type="Rewrite" url="clientArea/?clientID=1234" appendQueryString="true" logRewrittenUrl="true" />
</rule>
My second rule, however, I cannot get to work, so any help with this would be great
<rule name="Rewrite Everything Else after subdomain">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)clientA\.mysite\.com$" />
</conditions>
<action type="Rewrite" url="{R:0}" />
</rule>
Requesting things like http://clientA.mysite.com/example.js returns a 404 error.
Thanks for the time,
Kyle
If you have dedicated IP number for your site, you can add empty http binding to your site in IIS (right click on your site in IIS > Edit bindings > Add). Then add DNS 'A' record with value: * in your DNS configuration. As a result, every call to your IP will be maintained by your site.
You use a combination in inbound and outbound rewritting rules along with the Application Request Routing Module.
Inbound rule proxies the subfolder to the subdomain content. Outbound rule examines the response and replaces all instances of the subdomain in the response with your subfolder path.

IIS URL rewriting to redirect querystring addresses to MVC style path to preserve old links

I am trying to preserve old links such as index.php?pageid=123 to the now current /accounts/home. No part of the original URL has to be included in the redirect.
I have a big list of old page links and their new address. I thought it would be really simple to say index.php?pageid=123 = /accounts/home but I can't see how to do it. Most of the examples I see are the other way around whereby your site uses query string and you want your URLs to be SEO friendly. I'm using IIS 7.5 to rewrite.
Thanks
Got it sorted and it wasn't that hard really. Just needed to add the query string as a condition.
<rules>
<rule name="accounting" patternSyntax="Wildcard" stopProcessing="true">
<match url="index1.php" />
<conditions>
<add input="{QUERY_STRING}" pattern="page=accounts/accountsmain" />
</conditions>
<action type="Redirect" url="business-services/accounting.aspx" appendQueryString="false" />
</rule>
</rules>

Resources