Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

URL rewriting (shortened URL)

rodrigop8127141
Level 2
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!

2 Replies
Amit_Kumar
Community Advisor
Community Advisor

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

Amit_Kumar
Community Advisor
Community Advisor

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