AEM Cloud Service - Random Dispatcher Rules Filters


1) Add html to urls not ending with html and do a redirect


RewriteCond %{REQUEST_URI} !\.(html|css|jpg|png|gif|js|json)$ [NC]
RewriteRule ^(.*)$ $1.html [R=301,L]


2) Check if a header exists and do PT redirect say home to employee specific home page


RewriteCond %{HTTP:Eaem-Employee-Number} !^$
RewriteRule ^/content/eaem/us/en/home.html$ /content/eaem/us/en/employee-home.html [PT,L]


3) When a request comes from specific host and starts with a specific path redirect to another domain 


RewriteCond %{HTTP_HOST} ^qa-cloud\.mysite\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^dev-cloud\.mysite\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/content/eaem/us/en/internal/tech
RewriteRule ^/(.*)  https://internal.mysite.com/$1 [R=301,L]


4) Geographic blocking sample, if user is from US AND (from California OR Texas), then block access with 403 Forbidden error. Here it first sets the env var with a cookie value (eg. eaem_route_data=Country=US&State=CA) and later blocks the request checking its content


RewriteCond %{HTTP_COOKIE} eaem_route_data=([^;]+) [NC]
RewriteRule . - [E=eaem_route_data_env_var:%1]

RewriteCond %{ENV:eaem_route_data_env_var} Country=US
RewriteCond %{ENV:eaem_route_data_env_var} State=CA [OR]
RewriteCond %{ENV:eaem_route_data_env_var} State=TX
RewriteRule . - [F,L]


5) Show warning page when a cookie eaem_route_data exists with value CLOCKSTATUS=NOT_FOUND and employeeType=H, by extracting the value into env var eaem_route_data_env_var Say you'd like to view the clock warning page but you donot fall in that condition add the parameter clock_status=not_found in url. In both these cases it sets the env var clockNotFound value to 1 and later checks if the value is 1 and redirects user to a warning page


RewriteCond %{QUERY_STRING} "clock_status=not_found"
RewriteRule . - [E=clockNotFound:1]

RewriteCond %{HTTP_COOKIE} eaem_route_data=([^;]+) [NC]
RewriteRule . - [E=eaem_route_data_env_var:%1]

RewriteCond %{ENV:eaem_route_data_env_var} CLOCKSTATUS=NOT_FOUND
RewriteCond %{ENV:eaem_route_data_env_var} employeeType=H
RewriteRule . - [E=clockNotFound:1]

RewriteCond %{ENV:clockNotFound} "-eq 1"
RewriteRule ^/(.*)$ /content/eaem/us/en/errors/clock-warning.html?returnTo=/$1 [R=302,L]


6) Redirect specific paths to a different site using regular expressions 

        Examples of what gets redirected:

         /content/eaem/some.html → https://for-experience-aem.mysite.com/content/eaem/some.html

        /content/experience-aem/ → https://for-experience-aem.mysite.com/content/experience-aem/

        /content/dam/eaem/i.jpg → https://for-experience-aem.mysite.com/content/dam/eaem/i.jpg

        What stays on the current site:

        /content/eaem/for-this-site.html (excluded)

        /content/eaem/for-this-site/anything (excluded)


RewriteCond expr "%{REQUEST_URI} =~ m#^/content/((experience-aem|eaem)(\.html|/)|dam/eaem/)# && %{REQUEST_URI} !~ m#^/content/eaem/for-this-site(\.html|/)#" [NC]
RewriteRule ^/(.*)  https://for-experience-aem.mysite.com/$1 [R=301,L]


7)



No comments:

Post a Comment