Apache rewwrite - If / Else check | Community
Skip to main content
Employee
March 6, 2023

Apache rewwrite - If / Else check

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
		</If>
		<ElseIf "%{REQUEST_URI} =~ m#^/content/xyz#">
			Include conf.d/rewrites/xyz_rewrite.rules
		</ElseIf>
		
</IfModule>
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

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Employee
March 6, 2023

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- 

m#^/content/abc#

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-domains.html?lang=en#define-virtual-hosts-and-rewrite-rules-on-the-web-server 

[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-rewrite-rules-file-in-aem-as-a-cloud/td-p/427400 

Translate
Employee
March 6, 2023

Hi @vivekanand-mish ,

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.

Translate
Raja-Karuppsamy
New Participant
March 6, 2023

Can you please let us know your requirement?

Translate