Expand my Community achievements bar.

URL rewriting (shortened URL)

Avatar

Level 2

I want the pages of my site to be shortened like this:

Original URL: www.mysite.com/content/my-site/en/home.html

Shortened URL: www.mysite.com/home

 

Reading "SEO and URL Management Best Practices" document it states that:

"The SlingResourceResolver can be found at /system/console/config on any AEM instance and it is recommended that you build out the mappings that are needed to shorten URLs as regular expressions and include these configurations under a config.publish OsgiConfig node that is included in your build. Rather than doing your mappings in /etc/map"

 

It also states that implementing mapping using /etc/map can lead to some issues:

"While this is the approach that is documented in the official AEM and Sling documentation, the regular expression support provided by this implementation is limited in scope when compared to the options that are available to us by using the SlingResourceResolver directly. Additionally, implementing mappings in this way can lead to issues with dispatcher cache invalidation"

 

Another advantage of using SlingResourceResolver is that you can use resourceResolver.map() to apply the mapping to the outputed URLs.

Now I couldn't figure out how to use SlingResourceResolver to do the mapping. I created an OSGI config node (config.publish) but it hasn't worked. I was just able to accomplish the mapping by using /etc/map. I'm a little bit lost of how using SlingResourceResolver to do the mapping.

Any help is appreciated!

Thanks!

3 Replies

Avatar

Level 10

Rodrigo Proença wrote...

I want the pages of my site to be shortened like this:

Original URL: www.mysite.com/content/my-site/en/home.html

Shortened URL: www.mysite.com/home

 

Reading "SEO and URL Management Best Practices" document it states that:

"The SlingResourceResolver can be found at /system/console/config on any AEM instance and it is recommended that you build out the mappings that are needed to shorten URLs as regular expressions and include these configurations under a config.publish OsgiConfig node that is included in your build. Rather than doing your mappings in /etc/map"

 

It also states that implementing mapping using /etc/map can lead to some issues:

"While this is the approach that is documented in the official AEM and Sling documentation, the regular expression support provided by this implementation is limited in scope when compared to the options that are available to us by using the SlingResourceResolver directly. Additionally, implementing mappings in this way can lead to issues with dispatcher cache invalidation"

 

Another advantage of using SlingResourceResolver is that you can use resourceResolver.map() to apply the mapping to the outputed URLs.

Now I couldn't figure out how to use SlingResourceResolver to do the mapping. I created an OSGI config node (config.publish) but it hasn't worked. I was just able to accomplish the mapping by using /etc/map. I'm a little bit lost of how using SlingResourceResolver to do the mapping.

Any help is appreciated!

Thanks!

 

 

Hi,thanks for reaching out to the community.

You have a two part problem.
1. You have to remove .html
2. you have to shorten the urls.

Solution 1:

RewriteCond %{THE_REQUEST} ^/content/my-site/.* [NC]
RewriteRule ^ /invalid.html [L,R=404,NC]

# Handle request with no slash and no extension
RewriteCond %{REQUEST_URI} !^/content/dam/.*
RewriteCond %{REQUEST_URI} !.*\..*$
RewriteCond %{REQUEST_URI} !.*/$
RewriteRule (.*)$ $1/ [R,QSA]

# Handle requests to pages ending with .html
RewriteCond    %{REQUEST_URI} !^/content/dam/.*
RewriteCond    %{REQUEST_URI} .*.html$
RewriteRule    (.*).html$ $1/ [R,QSA]

# Handle requests to pages ending with a trailing slash
RewriteCond     %{REQUEST_URI} !^/content/dam
RewriteCond     %{REQUEST_URI} .*/$
RewriteCond     %{REQUEST_URI} !^/$
RewriteRule     (.*)/$ $1.html [PT,L,QSA]


Solution 2:

Step1: Go to System configuration i.e.  /system/console/configMgr>> Apache Sling Resource Resolver Factory
Step 2: Add a new URL mapping as /content/my-site/-/
Step 3: Go to System configuration i.e.  /system/console/configMgr>> Day CQ Link Checker transformer
Step 4: check Strip HTML Extension checkbox to strip the html from all existing URL

Regards,

Amit

Avatar

Level 1

hello, I have the same problem when I tried to short the urls, and remove .html, I followed your indications but some urls show an error.
for example:
https://aem65-publish1-qa.telcel.com/people/phone/friend/package/mb-friend/

Cannot serve request to /people/phone/friend/package/mb-friend/ on this server

do you know what is the reason of this issue?

 

 

Avatar

Level 10

I had added a slash in end as You are not using .html at the end of the file.
We should use a slash at the end of the URL for fast processing from cache and without losing SEO benefits.

Read this for more details:

https://moz.com/learn/seo/url

https://googlewebmastercentral.blogspot.com.au/2010/04/to-slash-or-not-to-slash.html