Expand my Community achievements bar.

SOLVED

Using Apache rewrite rules remove /content/smarter from all the page URLs

Avatar

Former Community Member

Hi all , we have our AEM project home page as smarter and underneath smarter.html we create all other website pages. Now using Apache .htaccess file using rewrite rules we need to remove /content/smarter from all the page URLs . For example  if the default page url is smarter.com/content/smarter/article1.html  should be displayed on browser as www.smarter.com/article1.html.  Please any help with the rewrite rule or 301 redirect method in Apache will greatly helpful and appreciated.    Thanks in advance

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You can handle it in AEM itself, simply create a sling mapping node under etc/host and you should be able to achieve all shortening of URL.

dev.day itself have an example to remove /content/ from the link path using sling mapping, kindly refer to following link - http://docs.adobe.com/docs/en/cq/5-6-1/deploying/resource_mapping.html#Creating%20Mapping%20Definiti...

They have mentioned example to truncate /content/ from the links, you can further extend the mapping to truncate your desired pattern from the URL.

Once you have the mapping configuration in place then AEM takes care of all the links and automatically shortens the URL that is rendered on them.

- Hope it helps

Runal

View solution in original post

10 Replies

Avatar

Correct answer by
Community Advisor

You can handle it in AEM itself, simply create a sling mapping node under etc/host and you should be able to achieve all shortening of URL.

dev.day itself have an example to remove /content/ from the link path using sling mapping, kindly refer to following link - http://docs.adobe.com/docs/en/cq/5-6-1/deploying/resource_mapping.html#Creating%20Mapping%20Definiti...

They have mentioned example to truncate /content/ from the links, you can further extend the mapping to truncate your desired pattern from the URL.

Once you have the mapping configuration in place then AEM takes care of all the links and automatically shortens the URL that is rendered on them.

- Hope it helps

Runal

Avatar

Level 3

Following snippet should rewrite short links without redirection. It also requires "DispatcherUseProcessedURL 1" directive set in the Dispatcher config

# opt-out proper URLs from rewriting RewriteRule ^/(apps|bin|etc|home|libs|tmp|var|content|dispatcher)/ - [L,NC] # rewrite everything else RewriteRule ^/(.+) /content/smarter/$1 [QSA,PT]

Avatar

Former Community Member

Can anybody get the exact rewriterule and correct steps where and all I need to make changes please.

 

I need to write the Rewrite Rule in .htaccess file in Apache  webserver.

What changes I need to make exactly in dispatcher and where in dispatcher like dispatcher.conf or dispatcher.any file

Any help in this regard is really helpfull

Avatar

Former Community Member

Hi ,

I modified the dispatcher.conf file  with 1

also i updated our .htaccess file with  below code you sent

  1. # opt-out proper URLs from rewriting
  2. RewriteRule ^/(apps|bin|etc|home|libs|tmp|var|content|dispatcher)/ - [L,NC]
  3. # rewrite everything else
  4. RewriteRule ^/(.+) /content/smarter/$1 [QSA,PT]

 

But still /content/smarter gets appended for any pages i open.

Any help in this regards will be really helpfull.

 

Thanks

Avatar

Level 3

You're doing two different things. mod_rewrite rewrites the http request. It doesn't touch the content of the page. If you don't change how you write out a URL then it will write out the full path. Yes, AEM will truncate the paths for you for the majority of the URLs but you'll need to configure AEM to do that in either the Resource Resolver OSGi config or in /etc/map. I'd recommend the link Runal put in his comment

Avatar

Community Advisor

Snap of Configuration:

[img]resourceresolver_mapping.jpg[/img]

This works as long as you are shortening the URL for one site. If you put the same rule for geometrixx-media as well and try to access localhost:4502/en.html it will still you to /content/geometrixx/en.html the 1st rule takes precedence but still geometrixx-media page will keep shortening the URL's.

So when you have multiple sites in repository for which you want to apply url shortening and expansion then I would suggest to for etc/map approach in case of single site URL shortening stick to resource resolver approach.

Hope it helps now.

- Runal

Avatar

Level 3

Hi Runal,

Can you please share the screenshot of the configuration again.