I prepared an image gallery which could be used with several page type models and provides images collection. The gallery is based on Javascript plugin. Gallery images are not rendered directly on the page. They are loaded on demand by the plugin. That’s why I need another version for crawlers where all images are available when the page is loaded.
I wrapped JavaScript gallery with the link to static page. When Javascript is enabled (it should be for all regular users) “dynamic” JS gallery is initialized and static link is removed. Otherwise the static link will point to the gallery page which is SEO friendly solution.
The URL to the “static” images list contains the Id of the page with gallery, for example /gallery?id=111. The HTML body of the gallery page is just the <ul> list with all images rendered as <img> tags.
Rewriting internal links
When I started to test the solution I noticed that the static link was always rewritten into another URL, because EPiServer recognized that link as internal address. I tried to use absolute URL like http://www.mysite.com/gallery?id=111 but it didn’t help.
After researching about how to prevent EPiServer from rewriting href attribute I found out that the solution was to use combination of two attributes on the link level:
- The id attribute has to be assigned.
- The EpiNoRewrite attribute has to be used.
Now the static link looks like:
1 2 3 |
<a id='static-page' href='/gallery?id=111' EpiNoRewrite='true' > <img src='images/img1' /> </a> |
The EpiNoRewrite attribute is configurable. It is stored in UrlPreventRewriteAttrebute property of EPiServer.Configuration.Settings. When value is not assigned, then the ‘EpiNoRewrite’ is used as a default. The solution seems to be quick and simple, however EPiserver is giving the following advice :
“For internal use, do not use. Defines the HTML attribute name that is used by the CMS 5 legacy editor when writing / parsing content”
I didn’t found any other way how to prevent EPiServer from rewriting URL addresses. Please leave some comments if you have any better solution for this.