Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Rewrite rules failing

Avatar

Level 4

We want to apply two rewrite rules

1. Make uppercase to lower case

2. Forward http to https

 

We have this in our dispatcher but it's failing deployment and messing other scripts - can anyone point out what is wrong here?

 

RewriteMap lowercase int:tolower
RewriteCond $1 [A-Z]
RewriteRule ^/?(.*)$ /${lowercase:$1} [R=301,L]

 


RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @aembytes 

 

Please use the below rule for upper case to lower case:

 

#Rule to ignore Case
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} ^(.*)[A-Z]+(.*)$
RewriteCond %{REQUEST_URI} !.*\..*$
RewriteRule (.*) ${lc:$1} [R,L]

 

For HTTP to HTTPS on Apache please use below:

 

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule /(.*) https://%{SERVER_NAME}/$1 [R,L]

 

If you are running apache on 443 then the above rule is not required as the HTTP to HTTPS redirect can be handled at the ALB and apache will always receive request with HTTPs traffic. This is something that I prefer.

 

Thanks!

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @aembytes 

 

Please use the below rule for upper case to lower case:

 

#Rule to ignore Case
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} ^(.*)[A-Z]+(.*)$
RewriteCond %{REQUEST_URI} !.*\..*$
RewriteRule (.*) ${lc:$1} [R,L]

 

For HTTP to HTTPS on Apache please use below:

 

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule /(.*) https://%{SERVER_NAME}/$1 [R,L]

 

If you are running apache on 443 then the above rule is not required as the HTTP to HTTPS redirect can be handled at the ALB and apache will always receive request with HTTPs traffic. This is something that I prefer.

 

Thanks!

Avatar

Community Advisor

Hi - Can you please check rewrite logs to see how request is flowing ? Please enable the rewrite log in the configuration if not done.

"LogLevel info rewrite:info".

 

Then - please do the necessary configuration changes.