Expand my Community achievements bar.

SOLVED

URL rewriting using apache mod_rewrite along with dispatcher causing request redirection.

Avatar

Former Community Member

Hi,

I have setup Apache 2.2 , AEM 5.6.1 and dispatcher on my windows machine. I have also setup Apache mod_rewrite rules to perform URL rewriting from external facing SEO URLs to internal AEM URLs. The issue I am facing is that after rewriting the URL the request is getting redirected, as a result of which the browser URL is changing to the internal AEM URL . I don't want to change the browser URL and would like it to still show the SEO URL.

I added a flag [PT] for the rewrite rule to ensure that that the processed URL is handed over to dispatcher. The rewrite worked and the page was picked from AEM by the dispatcher but the URL on the browser changed to the rewritten URL. I am not using the [R] flag in the rewrite rules so not sure why the URL is changing. One additional observation ,when I remove the dispatcher configuration from my httpd.conf, the URL on the browser does not change, so I am guessing it is the combination of Apache, mod_rewrite and dispatcher that is playing a trick or I may be missing something here. Has anyone faced a similar issue ? It would be great to hear from you.

  Example: http://localhost:8080/test/abc/def/ghj/test-results.html - SEO URL.  The SEO URL on the browser is changing to http://localhost:8080/content/myproj/en_us/home/mytest/search-index/test-results.html and the page is getting loaded by dispatcher which fetches it from CQ.
 
  httpd.conf
  <IfModule disp_apache2.c>
  DispatcherConfig conf/dispatcher_new.any
  DispatcherLog    logs/dispatcher.log
  DispatcherLogLevel 3
  DispatcherNoServerHeader 0
  DispatcherDeclineRoot 0
  DispatcherUseProcessedURL 1
  DispatcherPassError 0
</IfModule>
    
   <VirtualHost *:8080>
  ServerName localhost
  RewriteRule ^/test/(.*)/(.*)/(.*)/(.*)\.html$ /content/myproj/en_us/home/mytest/search-index/$4.html [PT]
  </VirtualHost>

Thanks in advance for your help.

Regards

Asit

1 Accepted Solution

Avatar

Correct answer by
Employee

In general, I think you'll find that if you use mod_rewriter, you *also* need to use the resource resolver configuration. mod_rewrite only handles inbound URLs and does not rewrite outbound content.

View solution in original post

7 Replies

Avatar

Former Community Member

Scott,

Thanks for the KB article. I have read this. It talks about using sling resource resolver but I am trying to  use Apache mod_rewrite instead.  I have used mod_rewrite in my past projects although on CQ5.5 and don't remember facing any issues.

I have looked at http://helpx.adobe.com/experience-manager/kb/RewriteURL.html  as well.Please let me know if using resource resolver is the only option in this case.

Avatar

Level 10

I would recommend using the resource resolver as specified in the KB that i referenced. Also -- please read the following for more great background information:

https://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html

Hope this helps

Avatar

Former Community Member

Some additional context , the site I am trying to setup is multidomain site setup on an AEM instance. Feels like setting up apache rewrite is easier than resource resolver so the dispatcher farm setup etc can be avoided. Can you please help me understand why this is not a recommended option. Also are there any licensing implications while using dispatcher farms (e.g. additional license etc).

Avatar

Former Community Member

I agree for URL rewriting in outbound content (to rewrite internal URLs to SEO URLs), resource resolver may be best suited.

My initial question around inbound is still kind of open -What could be the issue that is causing my Apache mod_rewrite/ dispatcher  to redirect my URL instead of just internal rewriting.

Also are there any licensing implications which I should be aware of while deciding on usage of dispatcher farms. I am assuming there aren't any but just wanted to be sure.

Avatar

Former Community Member

Thanks Scott. Will give this option a try.

Just for my understanding, https://dev.day.com/docs/en/cq/current/deploying/dispatcher/disp_domains.html says that web server level rewriting is also an option although resource resolver is recommended. I am curious if there is an issue when it comes to taking the web server URL rewriting option.

Avatar

Correct answer by
Employee

In general, I think you'll find that if you use mod_rewriter, you *also* need to use the resource resolver configuration. mod_rewrite only handles inbound URLs and does not rewrite outbound content.