Using Apache rewrite rules remove /content/smarter from all the page URLs | Community
Skip to main content
October 16, 2015
Solved

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

  • October 16, 2015
  • 10 replies
  • 11614 views

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

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 Runal_Trivedi

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%20Definitions%20in%20AEM

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

10 replies

Lokesh_Shivalingaiah
October 16, 2015

You can also use vanity URL in AEM itself  https://helpx.adobe.com/experience-manager/kb/vanity-urls.html

or you can configure the global redirect in apache http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

Runal_Trivedi
Runal_TrivediAccepted solution
October 16, 2015

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%20Definitions%20in%20AEM

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

October 16, 2015

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]
October 16, 2015

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

October 16, 2015

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

October 16, 2015
October 16, 2015

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

Runal_Trivedi
October 16, 2015

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

October 16, 2015

Awesome dude, it works

April 13, 2017

Hi Runal,

Can you please share the screenshot of the configuration again.