apache case insensitive URL

.htaccess Make URL Case Insensitive

When you migrate to Apache from other web servers such as IIS, you may need to deal with case sensitive URLs. By default, most popular platforms such as WordPress, Joomla, Drupal & Magento use case insensitive URLs in Apache. Still if you are facing problems with case sensitive URLs on your website, then here are the steps to make URL case insensitive in Apache using .htaccess.


.htaccess Make URL Case Insensitive

Here are the steps to make URL case insensitive in .htaccess for Apache server.


1. Open .htaccess

Open terminal and run the following command to open .htaccess file. Replace the path below with the path to your .htaccess file. We have used the default location of .htaccess file.

$ sudo vi /var/www/html/.htaccess

Also read : How to Make Subfolder Root using .htaccess


2. Make URLs case insensitive

Add the following line to make URLs case insensitive.

RewriteEngine on
CheckSpelling On 
CheckCaseOnly On

In this case, we use mod_spelling to check the case of URLs and fix them automatically.

Please note, if the above solution does not work for you, please add the following lines in .htaccess file instead.

RewriteMap tolowercase int:tolower  
RewriteRule ^(.*)$ ${tolowercase:$1}

In this case, Apache will automatically redirect all your URLs to lowercase ones.

Also read : How to Make Directory Inaccessible using .htaccess


3. Enable .htaccess (optional)

If you have not enabled .htaccess on your website, you can do so by opening Apache configuration file in a text editor.

$ sudo vi /etc/apache2/httpd.conf

Look for the following line.

AllowOverride none

Change it to the following line to enable .htaccess

AllowOverride All

Also read : How to Remove index.php using .htaccess


4. Restart Apache server

Restart Apache web server to apply changes

$ sudo service apache2 restart

That’s it. Open web browser and enter URL with uppercase or lowercase letters and your server will automatically send you to the right page, without displaying a 404:page not found error.

Also read : Apache Config File Location


Leave a Reply

Your email address will not be published. Required fields are marked *