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 Dispatcher - Multiple Redirect Rules File in VHosts

Avatar

Level 6

Hi AEM Community,

 

I have the below use case -

 

1. VHost File with redirect engine on and 2 rewrites inclusion

  <IfModule mod_rewrite.c>
RewriteEngine On
Include conf.d/rewrites/rewrite.rules
Include conf.d/rewrites/rewrites_brandA.rules
</IfModule>

  

The rewrites in rewrite.rules are executed but not the one in rewrites_brandA.rules

 

2. VHost File with 1 include and 1 rewrite instruction

<IfModule mod_rewrite.c>
RewriteEngine On
Include conf.d/rewrites/rewrite.rules
   RewriteRule "^(/?)$" "/content/brandA/us/en/home.html" [PT,L]
</IfModule>

 

The rewrite rule written later is also not executed by Dispatcher.

 

3. VHost File with rewrite.rules inclusion, and rewrite.rules can have any number of rules or further files inclusion.

  <IfModule mod_rewrite.c>
RewriteEngine On
Include conf.d/rewrites/rewrite.rules
</IfModule>

 

Rewrite.rules File - 

Include conf.d/rewrites/default_rewrite.rules
Include conf.d/rewrites/brandA_rewrite.rules

  

Why am I unable to write rules directly in vhost file or call custom rules file directly from vhost ?

As we will have a multi tenancy architecture, how do we map each rules file to custom domain from rewrite.rules file ?

 

I tried the below but had issues as my rewrite file had <LocationMatch> is not allowed inside <If>  context

<If "%{HTTP_HOST} == 'brandA.com'">
Include conf.d/rewrites/brandA_rewrite.rules
</If>
<If "%{HTTP_HOST} == 'publish.com'">
Include conf.d/rewrites/default_rewrite.rules
</If>

Can you please help with the best way to handle this ?

@arunpatidar , @Albin_Issac , @ @B_Sravan 

 

Thanks in advance,

Rohan Garg

1 Accepted Solution

Avatar

Correct answer by
Level 6

Hi All,

 

The issue is there because the windows based files in enabled vhosts and enabled farms are copies of available folders and not symlinks.

Pushing the same code in cloud image does not lead to any issue.

 

Hence, we do need symlinks in enabled vhosts and farms for files to properly work.

My local still has issue that when I create windows based symlinks using "mklink link target" I get the below error but the original problem is no longer there on cloud - 


C:\Users\rohan.garg\aem-sdk\dispatcher\aem-sdk-dispatcher-tools-2.0.91-windows\bin>docker_run D:\Project\Branches\Dispatcher_New\aemrepo\dispatcher\src host.docker.internal:4507 80
values.csv not found in deployment folder D:\Project\Branches\Dispatcher_New\aemrepo\dispatcher\src - using files in 'conf.d' and 'conf.dispatcher.d' subfolders directly
processing configuration subfolder 'conf.d'
processing configuration subfolder 'conf.dispatcher.d'
docker: Error response from daemon: mkdir D:\Project\Branches\Dispatcher_New\aemrepo\dispatcher\src\conf.dispatcher.d\enabled_farms\default.farm: Cannot create a file when that file already exists.
See 'docker run --help'.

View solution in original post

3 Replies

Avatar

Community Advisor

Hi @Rohan_Garg 

We are following the below structure to support multi sites.

Brand A - Virtual Host


<VirtualHost *:80>

ServerName www.brandA.com
ServerAlias www.brandA.com UAT Domain Stage Domain

RewriteEngine on

Include /etc/httpd/conf.d/rewrites/www_brandA_com.rules

/etc/httpd/conf.d/rewrites/www_brandA_com.rules

#For internal URLs

RewriteRule "^/test$" "%{HTTP:X-Forwarded-Proto}://%{SERVER_NAME}/elabeling.html" [R=301,NC,NE,L] #Environment specific details will be used while redireting

#For external redirects
RewriteRule "^/test1$" "https://www.google.com" [R=301,NC,NE,L] 


You should be able to create the same structure for the Brand B website; technically, it is possible to have two rewrite files included in vhost and add additional rules directly into the vhosts.


Please let me know if you need any additional details.
Regards

AI

www.albinsblog.com

Avatar

Level 6

Hi Albin, Thanks for your response.


When I try to include the 2 rewrite rules file as below, the second one is not being called upon.

It is only working if the include is written inside the first file i.e rewrite.rules.

 

  <IfModule mod_rewrite.c>
RewriteEngine On
Include conf.d/rewrites/rewrite.rules
Include /etc/httpd/conf.d/rewrites/domainA_rewrite.rules
</IfModule>

 

If I include any direct rules inside the VHost they are also not working - 

  <IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule "/content/brandA/us/en/home-page.html" "/content/brandA/us/en/home.html" [PT,L]
#Include conf.d/rewrites/rewrite.rules
</IfModule>
  

If the above rewrite rule is written in rewrite.rules or any other file included in rewrite.rules it is working fine.

Not sure what would cause this issue to occur.

Avatar

Correct answer by
Level 6

Hi All,

 

The issue is there because the windows based files in enabled vhosts and enabled farms are copies of available folders and not symlinks.

Pushing the same code in cloud image does not lead to any issue.

 

Hence, we do need symlinks in enabled vhosts and farms for files to properly work.

My local still has issue that when I create windows based symlinks using "mklink link target" I get the below error but the original problem is no longer there on cloud - 


C:\Users\rohan.garg\aem-sdk\dispatcher\aem-sdk-dispatcher-tools-2.0.91-windows\bin>docker_run D:\Project\Branches\Dispatcher_New\aemrepo\dispatcher\src host.docker.internal:4507 80
values.csv not found in deployment folder D:\Project\Branches\Dispatcher_New\aemrepo\dispatcher\src - using files in 'conf.d' and 'conf.dispatcher.d' subfolders directly
processing configuration subfolder 'conf.d'
processing configuration subfolder 'conf.dispatcher.d'
docker: Error response from daemon: mkdir D:\Project\Branches\Dispatcher_New\aemrepo\dispatcher\src\conf.dispatcher.d\enabled_farms\default.farm: Cannot create a file when that file already exists.
See 'docker run --help'.