AEM : How to lowcase source url of vanity_urls

Avatar

Avatar
Boost 1
Level 1
ForrestLi
Level 1

Like

1 like

Total Posts

10 posts

Correct reply

1 solution
Top badges earned
Boost 1
Validate 1
Affirm 1
View profile

Avatar
Boost 1
Level 1
ForrestLi
Level 1

Like

1 like

Total Posts

10 posts

Correct reply

1 solution
Top badges earned
Boost 1
Validate 1
Affirm 1
View profile
ForrestLi
Level 1

12-07-2021

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

206 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

206 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

12-07-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 

Answers (2)

Answers (2)

Avatar

Avatar
Contributor
Level 4
Bimmi_Soi
Level 4

Likes

68 likes

Total Posts

76 posts

Correct reply

24 solutions
Top badges earned
Contributor
Applaud 5
Boost 50
Ignite 1
Affirm 10
View profile

Avatar
Contributor
Level 4
Bimmi_Soi
Level 4

Likes

68 likes

Total Posts

76 posts

Correct reply

24 solutions
Top badges earned
Contributor
Applaud 5
Boost 50
Ignite 1
Affirm 10
View profile
Bimmi_Soi
Level 4

12-07-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

Avatar

Avatar
Boost 100
Level 6
Dipti_Chauhan
Level 6

Likes

111 likes

Total Posts

133 posts

Correct reply

39 solutions
Top badges earned
Boost 100
Give Back 10
Affirm 25
Boost 50
Boost 25
View profile

Avatar
Boost 100
Level 6
Dipti_Chauhan
Level 6

Likes

111 likes

Total Posts

133 posts

Correct reply

39 solutions
Top badges earned
Boost 100
Give Back 10
Affirm 25
Boost 50
Boost 25
View profile
Dipti_Chauhan
Level 6

12-07-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