Redirect Case Sensitive URL Using mod_rewrite and PHP
In Wordpress you may have noticed that the page slug defaults to lower case letters. I have learned that it does this in order to prevent potential problems or conflicts between Windows, Linux, and different browers.
Unfortunately, this can also cause problems.
For example, a user recently tried to visit Metro-East.com/bloggers by typing Metro-East.com/Bloggers into the address bar. (This is a simple entry page for bloggers and is not very interesting to look at.) The server treated the URLs as though they pointed to two different pages and so this caused an error because as far as it was concerned Metro-East.com/Bloggers did not exist.
I needed to find a way to make URLs not be case sensitive.
In other words, I had to find a way to redirect from the upper case URL to the lower case URL.
I searched for almost an hour trying to find a tutorial or explanation that I could understand. (My knowledge on these subjects is very limited and I pretty much need things spelled out for me very...very...slowly.)
I finally came across this article at TellinYa.com that explains how to use mod_rewrite on your .htaccess file to call a PHP function that will redirect from lower case to upper case URLs.
In order to implement this fix all you need is access to your server so that you can upload files.
Open your .htaccess file and add these lines:
-
# ReRoute Uppercase Containing URLs
-
RewriteCond %{REQUEST_URI} [A-Z]
-
RewriteRule ^(.*)$ lcaseurl\.php\?url=\/$1 [L,NC]
Then create a new file named lcaseurl.php.
Paste this code into lcaseurl.php and put it in your root directory:
That's it! Problem solved. You can test it out by visiting Metro-East.com/Blogs or Metro-East.com/blogs. They will both go to the same page. (A short list of the different blogs at my website.)
Here is a recent forum post on the subject that is not directly related to the solution I've put forth here. It was one of the most informative threads I found while surfing for answers.



















Leave your response!