Expand my Community achievements bar.

Apache rewwrite - If / Else check


Level 3
Hi Team, Need help in one scenario with Apache 2.4.8 rewrite. Trying to put If/Else condition based on "REQUEST_URI" in one of custom vhost file, but none of the files is getting included. Code in Vhost.
<IfModule mod_rewrite.c>
		ReWriteEngine	on
		LogLevel warn rewrite:info
		# Global rewrite include
		Include conf.d/rewrites/base_rewrite.rules
		<If "%{REQUEST_URI} =~ m#^/content/abc#">
			Include conf.d/rewrites/abc_rewrite.rules
		<ElseIf "%{REQUEST_URI} =~ m#^/content/xyz#">
			Include conf.d/rewrites/xyz_rewrite.rules
Logs :
init rewrite engine with requested uri /content/abc/in/en/home/test.html
pass through /content/abc/in/en/home/test.html
[perdir *If/] add path info postfix: /mnt/var/www/html/content -> /mnt/var/www/html/content/abc/in/en/home/test.html
[perdir *If/] applying pattern '(.*)' to uri '/mnt/var/www/html/content/abc/in/en/home/test.html'
[perdir *If/] pass through /mnt/var/www/html/content



3 Replies


Community Advisor

Can you please let us know your requirement?


Employee Advisor

Looks like you are trying to handle 2 different domain rewrites here. If that's true then your implementation approach is not right. Create 2 Vhosts and let each host include rewrite files dedicated to them -[0]. 

Anyway, you can refer apache expressions guide to put right conditional statement- [1]. Issue with your statement seems with regex- 


Can you just try m#/content/abc/# or /content/abc/


Also, please be aware that if you are on AEM cloud service- it does not support direct inclusion of custom rewrite file names- [2].


[0]- https://experienceleague.adobe.com/docs/experience-manager-dispatcher/using/configuring/dispatcher-d... 

[1]- https://httpd.apache.org/docs/2.4/expr.html 

[2]- https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-have-more-than-1-re... 

Hi @vivekanand-mishra ,

As per the condition mentioned it seems like they do have two rewrite rules working with different content paths respectively.

And both of the content paths will use same domain.