Inside Info: Canonical Link, Alias, Redirect, and Pathauto
The hpt canonical link serves the file
Linking directly to a file in Drupal can be surprisingly clumsy. The Hospital Price Transparency module makes it easy to link directly to the comprehensive machine-readable file by serving that file from the hpt
's canonical link. The form of the hpt canonical link /hpt/[id]
. In addition to making it easier to create a link to the file, this also means that we can update the file without having to manually update any links. That's a key feature since the pricing document is supposed to be updated at least yearly.
As an example, we can look at the hpt
we created in the previous page of this guide. We simply type /hpt/1
into the browser and we get served the contents of the json file.
If you have the redirect
module installed, you may have noticed that you were redirected to /hpt/1/123456789_DrupalHealth_standardcharges.json
.
Let's investigate what happened there.
The standardized alias conforms to cms.gov guidelines
The cms.gov guidelines specify that the file should be named following the pattern: [ein]_[hospitalname]_standardcharges.[json|xml|csv]
. To help fulfill this requirement, the Hospital Price Transparency module automatically generates and maintains an alias that meets the requirement. One of the tricks that the redirect
module does is redirect from the canonical link to the entity's alias. But the alias is also used any time the canonical link is generated by the link_generator
service. We can see this feature in action in the local task links.
We can go to the hpt
listing page...
...then go to edit that hpt
entity. We see the local tasks. If we click the "View"link, we are taken to the canonical route.
In this case we get served the contents of the json file from the alias /hpt/1/123456789_DrupalHealth_standardcharges.json
whether or not we have redirect
installed.
Using Pathauto
All this alias magic happens without Pathauto. Use of Pathauto is not recommended for hpt
entities. However, if you have a requirement that necessitates use of Pathauto, it is highly recommended that you end your pattern with either of the following:
-
/[hpt:ein]_[hpt:hospital_name]_standardcharges.[hpt:fid:entity:extension]
-
/[hpt:file_alias]
In order to use the second option, you must add hpt:file_alias
to the list of safe tokens in the Pathauto configuration. Other patterns may not meet the cms.gov guidelines for the filename.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion