Some time ago I asked this question on the English site without getting an answer.
It happens that I am applying the rule RewriteRule [NC]
to mysite.com so that, regardless of the writing, uppercase or lowercase, it accepts the request in the URI.
I have the following configuration in my file.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80 [NC]
RewriteRule ^(.*)$ https://misitio.com/$1 [R,L,NC]
It works for the main domain, but not for folders or directories (eg mysite.com/contact )
According to the Apache documentation this instruction should work globally. This is what I have tried:
RewriteMap lowercase int:tolower RewriteCond %{HTTP_HOST} [A-Z]
RewriteRule (.*) http://${lowercase:%{HTTP_HOST}}$1 [R,L,NC]
I saw the option to apply this rule to each directory independently, but pages are created dynamically and controlling them this way doesn't seem like the best option to me.
I also saw this answer on SOen , but I don't quite understand it to apply to my site. Any suggestion?
Thank you very much.
As discussed in askapache's Htaccess to Redirect Uppercase to Lowercase , there are at least three ways to force everything typed in the browser bar to be converted to lowercase.
Everything will depend on whether you have access to the Apache configuration file or not (generally in shared hosting they do not give you access to that file).
If you don't have access to the configuration file
directly in the file
.htaccess
In that case you can put these rules, keeping in mind that this should go at the top of your
.htaccess
. It should at least go above any otherRewriteRule
. This is because it uses a loop, until there are no more uppercase characters to convert, it will keep starting at the first rewrite rule ofHASCAPS: TRUE
. This is actually very fast and won't slow anything down.I have this implemented on my site and it works without a problem. Although I haven't been able to get it to work on sub directories, it does work on the root of my site. My problem was that I created a program to save the number of visits to my site for each URL using the Google Analytics API and I couldn't do the filters correctly by URL when the user typed using any capital letters... currently everything that enters the site arrives in lowercase.
If you have access to the configuration file
You can do it in either of these two ways:
Using
RewriteMap
in filehttpd.conf
This is technically a faster way to do it, but it has to be in the file
httpd.conf
, not the.htaccess
:Wearing
mod_speling
You can also enable the apache module
mod_speling
, as follows:Other options
Since you say that in your context directories are created freely by users in some way , perhaps it would be advisable to control the code that creates those directories, causing the contents to be created in already fixed directories. As for URLs, you could also control that they are always created in lower case, for example, by PHP promotion always control that file names and extensions are converted to lower case before saving them on the server.