AEM : How to lowcase source url of vanity_urls | Community
Skip to main content
Level 3
July 12, 2021
Solved

AEM : How to lowcase source url of vanity_urls

  • July 12, 2021
  • 3 replies
  • 3419 views

I configed the  vanity_urls in the dispatcher.

 

/vanity_urls { /url "/libs/granite/dispatcher/content/vanityUrls.html" /file "/tmp/vanity_urls" /delay 300 }

 

The values of the /libs/granite/dispatcher/content/vanityUrls.html are

 

test1 test2 test3

 

 

In the AEM, the vanity url maps are 

 

test1 mysite/home test2 mysite/about test3 mysite/product

 

 

Now, If I enter the https://docker.demo.com/test1, it will redirect to the  https://docker.demo.com/mysite/home

But If I enter the https://docker.demo.com/TEST1, I will get a 404 error.

 

Expected:

If I enter the https://docker.demo.com/TEST1, it would first convert to the  https://docker.demo.com/test1, and then redirect to the https://docker.demo.com/mysite/home.

If I enter the https://docker.demo.com/TEST6,  since test6 is not in the vanity_urls, so it will direct to the https://docker.demo.com/TEST6 and not convert it to lowcase.

 

Does anyone know how to achieve it?

 

BTW : I configed the ErrorDocument in the apache. If a page is not found, it will redirect to the error page. So I can't change the 404.jsp of error handle (sling\servlet\errorhandler) to achiece it. 

ErrorDocument 404 /home/errors/404.html

 

Thanks,

Forrest

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Asutosh_Jena_

Hi @forrestli 

 

Please add the below rule in your v-host file and the case related issue will be resolved.

 

##Rule to ignore case
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} ^(.*)[A-Z]+(.*)$
RewriteCond %{REQUEST_URI} !.*\..*$
RewriteRule (.*) ${lc:$1} [R=301,L] 

Hope this helps!

Thanks 

3 replies

Dipti_Chauhan
Community Advisor
Community Advisor
July 12, 2021

Hi @forrestli 

 Refer this article for case insensitive urls setup on dispatcher: https://blogs.perficient.com/2017/10/17/mastering-the-aem-dispatcher-part-2-case-insensitive-urls/

 

Thanks

Dipti

ForrestLiAuthor
Level 3
July 12, 2021

Hi @dipti_chauhan 

 

I checked that articel. Enable mod_speling will cause some unexpected error for me. The RewriteMap is not work for vanity url. That article can’t achieve my requirement.

 

Thanks,

Forrest

Asutosh_Jena_
Community Advisor
Asutosh_Jena_Community AdvisorAccepted solution
Community Advisor
July 12, 2021

Hi @forrestli 

 

Please add the below rule in your v-host file and the case related issue will be resolved.

 

##Rule to ignore case
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} ^(.*)[A-Z]+(.*)$
RewriteCond %{REQUEST_URI} !.*\..*$
RewriteRule (.*) ${lc:$1} [R=301,L] 

Hope this helps!

Thanks 

ForrestLiAuthor
Level 3
July 12, 2021

Hi @asutosh_jena_ 

 

This can achieve my requirement. But it will prevent me from accessing pages that contain capital letters (e.g. https://docker.demo.com/TEST6).

 

Thanks,

Forrest

Adobe Employee
July 12, 2021

Hi @forrestli ,

When you migrate from a legacy system, you’ll usually get a list of legacy vanity URLs and legacy URLs which need redirects. Apache httpd’s redirect maps make this an easy process, but like everything else in Apache, they are case sensitive.

So how do we work around this? There is a built-in redirect map in Apache which lowercases whatever it receives. We can use this to first downcase the URL, then check for it in the redirect map.

 

RewriteMap map.legacy txt:/etc/httpd/conf.d/map-legacy.txt
RewriteMap lc int:tolower
RewriteCond ${map.legacy:${lc:$1}} !=""
RewriteRule ^(.*)$ ${map.legacy:${lc:$1}|/} [L,R=301]

 

You will also need to lowercase the redirect source URLs so they will match, for example:

 

/vanity1 https://www.site.com/afolder/apage.html
/vanity2 https://apps.asite.com/An-App/In-IIS.aspx    

Or else try :

 

RewriteEngine onRewriteBase /
RewriteMap lowercase int:tolowerRewriteCond $1 [A-Z]
RewriteRule ^/?(.*)$ /${lowercase:$1} [R=301,L]

 

 

Hope it helps!!

Thanks

ForrestLiAuthor
Level 3
July 12, 2021

Hi @bimmiso 

I need to lowcase source url of vanity URLs instead of the legacy URLs. This does not achieve my requirement.

 

Thanks,

Forrest