Forum Moderators: phranque
RewriteCond %{HTTP_HOST} ^(?:(?:www|ww2)\.)?(\w+)\. [NC]
RewriteRule ^ - [E=domain:%1] RewriteCond %{HTTP_HOST} ^(?:(?:www|ww2)\.)?(\w+)\. [NC]
RewriteRule ^ - [E=domain:%1]
RewriteCond %{ENV:domain} ^a(\w+)$
RewriteRule ^ - [E=ucDomain:A%1]
RewriteCond %{ENV:domain} ^b(\w+)$
RewriteRule ^ - [E=ucDomain:B%1]
...
RewriteCond %{ENV:domain} ^z(\w+)$
RewriteRule ^ - [E=ucDomain:Z%1]
RewriteMap uc int:toupper
RewriteCond %{ENV:domain} ^(\w)([\w-]+)$
RewriteRule ^ - [E=ucDomain:${uc:%1}%2]
[edited by: w3dk at 8:48 pm (utc) on Feb 9, 2021]
However, I would do this in your application logic/script, not Apache.
I know that I could do it manually with 26 rules, but is there a better way?
I'm making a point to learn more about Apache just for the sake of my own education and keeping things interesting
I'm really not too concerned with bots getting the right variable here
Correct me if I'm wrong, but I HAVE to add RewriteMap to the httpd.conf file, right? Not to /etc/apache2/conf.d/userdata/foo.conf ? I've been hesitant to mess with that since cPanel tends to overwrite it when it updates.
RewriteCond expr "toupper(%{ENV:domain}).'@'.tolower(%{ENV:domain}) =~ /(.)[^@]+@.(.*)/"
RewriteRule ^ - [E=ucDomain:%1%2]
If the file ends in ".conf" then you are already in the right ballpark. I thought all your recent posts are about moving directives from .htaccess to the server config?
you should spend some time on the lowercasing algorithm in jdmorgan's 2nd post in this thread: