Redirect A Url To An External Domain In Umbraco 7
One of my clients has an Umbraco 7 site that pretty much takes care of itself other than a few minor content updates here and there. Today that client asked we set up a redirect from an internal URL to an external domain for their job postings. Normally this is an easy change using IIS rewrites in the web.config with the IIS Rewrite Module. But this site is hosted on GoDaddy and like all GoDaddy things, what I thought was easy turned out to be a bit more of a challenge.
After a bit of research I found you can redirect Umbraco URLs using the UrlRewritingNet component that’s built into Umbraco 7. Here’s an example of how to configure Umbraco 7 to redirect an internal URL to an external domain using the UrlRewriting.config config file.
To configure a URL rewrite open the configuration file located at /Config/UrlRewriting.config and add a rewrite rule like the example below. I found that rewriting to an external URL was more tricky than an internal virtual URL so here are a couple specifics to keep in mind when setting up a new rule for an external URL:
- Set rewriteOnlyVirtualUrls=”false” attribute inside <urlrewritingnet
- The virtualUrl is the source URL of the page you are redirecting from. The value in this attribute must start with http(s)://domain otherwise the rule will be ignored
- destinationUrl is the destination for the redirect
- redirect should be set to “Domain”
Here’s an example of the UrlRewriting.config file that will redirect an internal URL to an external domain.
<?xml version="1.0" encoding="utf-8"?> <urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07" rewriteOnlyVirtualUrls="false" > <rewrites> <add name="redirectexample" virtualUrl="https://example.com/jobs?$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="https://clintmcmahon.com" ignoreCase="true" redirectMode="Permanent" redirect="Domain" /> </rewrites> </urlrewritingnet>