Examples of Formatting Redirects


Redirects capture any string after the From value, including querystrings. You can also add querystrings to the To value, which can be useful for site tracking implementations.

If your site uses redirects, it's important to understand the significance of the leading and trailing slashes (/) in the From and To fields.

Caution
Clear your browser cache after modifying existing redirects to ensure the old configuration is not applied. We recommend that you always test published redirects using Private Browsing mode because this mode does not cache redirects after closing the browser. See Stack Overflow: Browser Cache/Expiry for details.

From Field

A leading slash in the From field provides a wildcard match at the folder level. However, partial matches aren't supported. For example, if the path is [site]/news, the From field provides a match for [site]/news/ (exact) and not for [site]/news_article (partial).

A From field that ends with a trailing slash matches only complete strings. For example, each path maps to a particular xID (e.g., x220.xml): [site]/news, [site]/news/, and [site]/news/today. The path [site]/news_articles would not match x220.xml because the key element of the request (news_articles) does not exactly match the field (news).

To Field

A leading slash in the To field has an effect similar to the From field. For example, /promotion/page1 and /promotion/page2 go to /news. Placing a trailing slash in the To field allows extended path elements to pass from the From field.

In this example, a request for [site]/news/today returns www.news.com/today.

A leading and trailing slash in the To field also passes these elements.

This redirect makes /promotion/page1 redirect to /news/page1.

Updating Redirects

Full and incremental publishes update redirects on the DSS. The settings file in settings\redirects.xml reflects the redirect updates after you execute a publish.

Note
Each entry in Redirects is written in RavenDB as a redirects/[#] document, which has a Redirects document collection.

Redirects Reference Table

Use the table below as a reference to format redirects. In the table, the site_url tag denotes the URL of the DSS site, and the external_url tag denotes an external website (e.g., https://www.google.com).

Additional Information
When you format redirects, the following occurs:
  • The redirects process looks for an explicit match in the To value first. If no explicit match exists, the process attempts to match an implicit partial-match rule.
  • The structured URL resolution process starts towards the end of the redirects resolution.
  • Leading slashes in the To value always represent the baseURL value.
    • In the case of a DSS configured as a virtual directory, this causes the redirect to drop the virtual directory folder on redirect and use the baseURL value instead-unless the To value is a valid page xID. Example: DSS configured as a virtual directory: http://www.mrmeeseeks.com/cando/ with a page named LookAtMe.html with the xID of x55 published to the site.
      • Redirect: From = /hello, To = /world. Result: http://www.mrmeeseeks.com/world
      • Redirect: From = /idontknow, To = /x55. Result: http://www.mrmeeseeks.com/cando/LooktAtMe.html

FromToExpected BehaviorExample matchesExpected Result
xID1.xmlxID2.xmlMatch exact From to To.
Note
This will then resolve the structured URL for the xID.

http://contoso.com/xID1.xml

http://contoso.com/xID2.xml

hello

world

http://differentsite.org

Match exact From to To.

http://contoso.com/hello

http://contoso.com/world

http://differentsite.org

/hello

world

Match exact From to To.

http://contoso.com/hello

http://contoso.com/world

/hello

/world

Match exact From to To.
Note
The leading slash in the To value results in a traversal back by one directory if you run a DSS as a virtual directory.

http://contoso.com/hello

http://contoso.com/world

helloworld/Match exact From to To.

http://contoso.com/hello

http://contoso.com/world

hello/

world/http://differentsite.org/

Match exact From to To.
Note
This also appends anything after the From value to the end of the To value result.

http://contoso.com/hello

http://contoso.com/hello/darling

http://contoso.com/hello/darling/there

http://contoso.com/world

http://contoso.com/world/darling

http://contoso.com/world/darling/there

http://differentsite.org/world

http://differentsite.org/world/darlinghttp://differentsite.org/world/darling/there

/hello/world/Match exact From to To.
Note
This also appends anything after the From value to the end of the To value result.

http://contoso.com/hello

http://contoso.com/hello/darling

http://contoso.com/hello/darling/there

http://contoso.com/hello?foo=bar

http://contoso.com/world

http://contoso.com/world/darling

http://contoso.com/world/darling/there

http://contoso.com/world?foo=bar

/hello/world/new/planet

Match exact From to To.

Note
The leading slash in the To value results in a traversal back by one directory if you run a DSS as a virtual directory.

http://contoso.com/hello/world

http://contoso.com/new/planet

/hello/world/new/planet/

Match exact From to To.

Note
This also appends anything after the From value to the end of the To value result.

http://contoso.com/hello/world

http://contoso.com/hello/world/pluto

http://contoso.com/new/planet

http://contoso.com/new/planet/pluto

http://contoso.com/hello

http://contoso.com/world

http://contoso.com/xID.xml

Match exact From to To

Note
If the xID does not include .xml, the xID does a literal redirect to the To value and doesn't process the xID value to a structured URL result.

http://contoso.com/hello

http://contoso.com/world

http://contoso.com/hello/world/

http://contoso.com/newWorld/

Match exact From to To. Any values after ending slash in From triggers a redirect.

Note
This does not append to the end of the To value, including querystrings.

http://contoso.com/hello/world/

http://contoso.com/hello/world/lonely/planet/

http://contoso.com/newWorld/

http://contoso.com/hello/world/http://differentsite.org/new/World/

Match exact From to To. Any values after the trailing slash in From triggers a redirect.

Note
This does not append to the end of the To value, including querystrings.

http://contoso.com/hello/world/

http://contoso.com/hello/world/lonely/planet/

http://differentsite.org/new/World/

 

Related Topics