make .htaccess redirect case sensitive

Posted on

make .htaccess redirect case sensitive – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, .htaccess, tomcat, , .

I need to redirect to folders from port 80 to 8080
1. Default index to /somename
2. /admin to /somename

I tried a .htaccess to

RewriteEngine on
Redirect / http://example.com:8080/somename
Redirect /admin http://example.com:8080/someAdmin

But i’m running JSP so the folder name i used is someAdmin (note A uppercase)
It’s impossible for me to change the path in my code (sorry about it)

Problem
So because of this i’m getting error page (CASE sEnSiTive) redirection
(Automatically it converts to small case in browser)

AddOn
I’ll be happy if it .htaccess could mask 8080 port from user via reverse proxy.

RewriteEngine on
RewriteCond  %{SERVER_PORT} !^8080$
RewriteRule ^(.*) http://%{SERVER_NAME}:8080/somefolder%{REQUEST_URI}
Redirect /admin http://%{SERVER_NAME}:8080/someAdmin

Solution :

That’s odd that Redirect is behaving like that. I don’t have an Apache instance handy right now to verify that mod_alias is supposed to behave like that, but if it’s not going to respect case in a target location, then I suppose just use mod_rewrite, since you’re loading it anyway:

RewriteBase /
RewriteRule ^$ http://example.com:8080/somename [R,L]
RewriteRule ^admin$ http://example.com:8080/someAdmin [R,L]

For reverse proxying, it looks like you’d want to proxy instead of, as opposed to in addition to, the redirects?

For what you need, ProxyPass would work just fine, but it doesn’t play nice with .htaccess. If you have the option, don’t config this in .htaccess, use ProxyPass instead. If you don’t, then mod_rewrite should do the trick:

RewriteBase /
RewriteRule ^admin(.*)$ http://example.com:8080/someAdmin$1 [R,L]
RewriteRule ^(.*)$ http://example.com:8080/somename/$1 [R,L]

Leave a Reply

Your email address will not be published.