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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM : How to lowcase source url of vanity_urls

ForrestLi
Level 2
Level 2

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

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution
Asutosh_Jena_
Correct answer by
Community Advisor
Community Advisor

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 

View solution in original post

0 Replies
ForrestLi
Level 2
Level 2

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_
Correct answer by
Community Advisor
Community Advisor

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 

View solution in original post

ForrestLi
Level 2
Level 2

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

Asutosh_Jena_
Community Advisor
Community Advisor

Hi @ForrestLi 

 

As per the SEO Practice, all the URLs should be in lower case.

So if you use the above rule, all the URLs will be forcefully converted into lower case and then the request will be sent to publish instance to get the resource.

 

If your request URL is https://docker.demo.com/TEST6 then it will convert into https://docker.demo.com/test6 and then resolve the content. If you have the page in publish available with name as test6 then it will resolve and should not be an issue for you.

 

If still you want to retain few URLs in Upper case and do not want to convert into Lower case then use the below rule and exclude the specific URLs. You can use any specific pattern also to skip any specfic path exclusion.

 

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

Thanks!

Bimmi_Soi
Community Advisor
Community Advisor

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

ForrestLi
Level 2
Level 2

Hi @Bimmi_Soi 

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

 

Thanks,

Forrest

Bimmi_Soi
Community Advisor
Community Advisor

@ForrestLi ,

 

Can you please try to rewrite your url as below

 

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

 Hope this helps.

 

Thanks