Rewrite rules failing | Community
Skip to main content
Level 4
September 24, 2021
Solved

Rewrite rules failing

  • September 24, 2021
  • 2 replies
  • 1250 views

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]

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

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!

2 replies

Asutosh_Jena_
Community Advisor
Asutosh_Jena_Community AdvisorAccepted solution
Community Advisor
September 24, 2021

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!

Raja-Karuppsamy
Community Advisor
Community Advisor
September 24, 2021

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.