Vanity URLs are alternate reference paths to internal or external URL's. When you create a Vanity URL, a user may access the same page or file using two different URLs - the normal path to the page or file as it appears in the Site Browser tree, and the URL specified in the Vanity URL.
- Using Vanity URLs
- The Vanity URLs Portlet
- Redirect Types
- Redirecting Multiple URLs Using Regular Expressions
- Blocked URLs
- Search Engine Optimization (SEO)
Using Vanity URLs
You may use Vanity URLs to redirect to any of the following:
- Files (including images)
- URL Mapped content items
- In other words, the URL that displays an individual URL-mapped content item
- Multiple pages, files, or URL Mapped content items (using a regular expression).
You may not use Vanity URLs to redirect to any of the following:
- Individual content items (except when URL Mapped to a specific URL).
- The Detail page of a URL Mapped Content Type.
The Permissions on a Vanity URL itself determine which users can access the URL specified in the Vanity URL URI field. These permissions do not have any effect on the permissions of the object (page, file, path, etc.) that the Vanity URL redirects to in the Forward To field.
For a user to access any object via a Vanity URL, the user must have permissions to view both the Vanity URL and the object the Vanity URL redirects to.
For example, if the permissions on a page are restricted to prevent anonymous users from viewing the page, and you create a Vanity URL which redirects users to that page, anonymous users will still not be able to view that page, even if the Vanity URL permissions are set to allow anonymous users to access the Vanity URL.
Some common uses of Vanity URLs include:
- Give site visitors a more user-friendly or memorable way of reaching an HTML page or File (which might actually live “buried” in a much deeper path).
- Redirect URLs to a new location when the path to a page or file has changed.
- Help track links from different sources (such as different promotions) to the same page on your site.
The Vanity URLs Tool
Vanity URLs may be viewed from either the Content Search tool (Content -> Search) or the Vanity URLs tool (Marketing -> Vanity URLs). Both views display Vanity URLs using the same display format as the Content Search screen.
Adding or Editing a Vanity URL
When creating or editing a Vanity URL, you must give the Vanity URL a Title, select which Host the Vanity URL applies to (or “All Hosts”), and supply a “virtual path” to the destination in the URL field. You can either type in the URL for a link or use the click here to browse button to browse for an internal destination.
Note: Please see Redirect Types, below, for an explanation of how the URL entry affects what type of redirect is performed.
In the example below, a Vanity URL (www.dotcms.org/documentation) has been created that will display the page
Once you have saved the Vanity URL, test the new “virtual” path by typing it directly into your web browser.
- Vanity URLs may only contain valid URL characters.
- All letters in Vanity URLs will be forced lower-case letters.
- When redirecting TO a file or page, the Vanity URL will work correctly whether or not the Uri field includes a trailing slash (
- BUT to access the Vanity URL from the browser, the Uri will not be recognized if it includes a trailing slash (whether or not the Uri field includes one).
- You may redirect to a page or file in any folder on your site (even one which is within a folder which is not set to Show on Menu).
- 200 Forward
- 301 Permanent Redirect
- 302 Temporary Redirect
When you set the redirect type to 200 Forward, dotCMS will perform a “requestdispatcher” forward (a transparent forward) whenever a user accesses the specified URL. The URL in the user's browser will not be changed.
Vanity URLs created in this way are true URL's which maintain their presence in a website browser's navigation toolbar even after the destination HTML page or file is reached.
Important: Since the URL in the user's browser does not change with a forward, if there are links on the destination page which are relative to the destination page itself, these links may not work since they will be referenced from the Vanity URL's URL local (e.g. /documentation) rather than from the actual location of those files in your Site Browser tree (e.g. /docs/latest). To ensure that links in the destination page will work even when a forward is used, you should reference all URLs relative to the root of your Site Browser tree (e.g. “/docs/latest/vanity-urls”) rather than relative to the page or folder the page is in (e.g. just “vanity-urls”).
When you set the Action to a Redirect (either 301 or 302), dotCMS will redirect the user to the Forward to URL whenever a user accesses the specified URI. When the user is redirected, the URL displayed in the user's browser will change to display the Forward To: URL, and all links on the destination page will be referenced from the normal path of the page (as displayed in the Site Browser tree), ensuring that all relative links on the page work properly after the redirect.
Redirecting Multiple URLs Using Regular Expressions
You may configure a single Vanity URL to match multiple URLs by using a regular expression as part of the Uri field. The Vanity URL will match all URLs which match the regular expression in the Uri field, and will replace them with the URL specified in the Forward To field.
If you put a simple string in the Forward To field, then all URLs which match the regular expression will forward to the single Forward To URL. However you can also specify parameters in the Uri field regular expression, and then copy the values of those parameters into the URL specified in the Forward To field.
- To specify a parameter in the Uri field, surround the regular expression to match with parentheses (
- You may include up to 9 parameters in the Uri field, each surrounded by parentheses.
- To include the value of a matching parameter in the Forward To field, use a dollar sign followed by the number of the parameter (starting with number 1, in the order the parameters appear in the Uri field).
For example, if your Uri field is
$1in the Forward To field will be replaced with the part of the URL that matches the regular expression
$2in the Forward To field will be replaced with the part of the URL that matches the regular expression
Example: Moving a Top-Level Folder
The following example values redirect all URLs pointing to the top-level “/services” folder to a sub-folder named “cloud” under the “/products” top-level folder.
Using this type of a regular expression parameter in your Vanity URL enables you to move folders within your site freely, creating a single Vanity URL to redirect any requests that go to any pages or files in the old location of the folder.
As a security precaution, certain URLs are not allowed in vanity URLs (e.g. “black-listed”). The following is a list of all URL branches that are not allowed; you will not be allowed to save any Vanity URL which begins with one of these strings:
Search Engine Optimization (SEO)
On Google and some other search engines, the location of your page in search results may change if the same content is available via two different URLs (such as with a Vanity URL and the page the Vanity URL points to). To maximize your page ranking in search results, you may specify the canonical URL for any Page Asset. This directs the search engines to combine the search result data for the main page and any Vanity URLs linked to that page.
To specify the canonical URL, open the Page Properties, select the Advanced Properties tab, and edit the Canonical URL field. Once this field has been set, dotCMS will automatically add a canonical URL link to the page header each time the page is displayed (either directly or through a Vanity URL).
For information on other ways to maximize search engine optimization for pages referenced by Vanity URLs, please see Use canonical URLs on the Google help site.