0

UPDATED ON 23-08-2017, see section below

I want make URLs under RedHat 7 case-insentitive just before the Apache access to the declared directory.

I tried with mod_rewrite and mod_speling. No one of them works. I know that Linux is a case-sensitive operating system.

My target is to make the URL for my API case-insentitive. I already have declared a minimum setting for httpd, just it even runs. I also added the required modules for a specific task or setting.

What shall I do? Or just even better: Please explain to me how is it possible or why it doesn't work?


UPDATED ON 23-08-2017

I get an error of 403 (Forbidden) with the message that I don't have permission to access /API/v1/ on the server when I call my API like this:

https://servername/API/v1

Here is an extract of the Apache (httpd) setting:

## Rewriting URLs
# The URL rewrite engine switch
RewriteEngine On

# The rewrite map for certain parameters like function()
RewriteMap lowercase int:tolower

# Make all HTTP request to lowercase
<If "%{REQUEST_URI} =~ m#[A-Z]#">
  RewriteCond %{REQUEST_URI} [A-Z]
  RewriteRule (.*) ${lowercase:$1} [L]
</If>

# Make all HTTP request to HTTPS
<If "%{HTTPS} == 'off'">
  RewriteCond %{HTTPS} off [NC]
  RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,NC,L]
</If>

## Directory Access
# Deny access Serverroot  - Never delete this!
<Directory />
  Require all denied
  AllowOverride None
  Options None
</Directory>

# Allow documents to be served from the DocumentRoot
<Directory "/path/to/my/api/v1">
  Require all granted

  DirectoryIndex index.php
  Options +Indexes +FollowSymLinks
</Directory>
t.koelpin
  • 1
  • 2

1 Answers1

0

Simply make all of your URLs lowercase, period. Any upper case is converted to lower case by redirecting to the lower case equivalent. This makes it case insensitive by not allowing any uppercase to be used and transparently changing the url to all lowercase.

Apache .htaccess code:

<IfModule mod_rewrite.c>
RewriteMap lc int:tolower
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ ${lc:$1} [R=301,L]
</IfModule>
Elliot Huffman
  • 1,229
  • 1
  • 12
  • 25
  • Did not work, but I am going to update my question above. – t.koelpin Aug 23 '17 at 05:43
  • @t.koelpin Did you put that in a `.htaccess` file? Also, if you did, did you remove your config settings and allow overriding via the virtual host file? So, put the `.htaccess` file in your document root, allow overriding for your document root and make sure that there are no duplicate settings in your apache config. http://httpd.apache.org/docs/current/mod/core.html#allowoverride – Elliot Huffman Aug 23 '17 at 09:24
  • No, I didn't put that in a .htaccess file and I never will do this for security-related reasons. And why should I do that? I have access to the apache config because I am the project supporter. – t.koelpin Aug 23 '17 at 09:40
  • I am not aware of any security related issues to using `.htaccess`, unless you misconfigure it. Can you inform me on why your having issues in this department? `.htaccess` is a good way to specify a per site setup for the url's your trying to affect. all you do is just plop a `.htaccess` file in the hosting directory and voilà, you have permissions and configurations for that directory. – Elliot Huffman Aug 23 '17 at 10:20
  • I only want to rewrite all URLs to the lowercase and redirect all HTTP-Request to HTTPS. Nothing more. There must be a global configuration. Why should I rewrite exactly the same code for each folder? – t.koelpin Aug 23 '17 at 10:51
  • Just put the htaccess in the parent folder, I don't generally recommend on adding directives to the config but that is up to you. – Elliot Huffman Aug 23 '17 at 20:16