Htaccess rewrite/redirect

I’m trying to do a redirect to account for a case sensitive folder, I can’t seem to get it right though. what am I missing?

RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

${HTTP_HOST} only contains the host, not the path. What I would do is

RewriteRule ^ICANRide - [S=1]
RewriteRule ^icanride/(.*)$ /ICANRide/$1 [L,R=301,NC]

The first rule checks if the URL starts with ICANRide, and if it does skip the next rule (because it’s already in the correct case and nothing needs to be fixed).

So the next rule only fires if the first rule didn’t tell Apache to skip it, i.e. the URL is certainly not starting with ICANRide at this point. So we check if the URL starts with “icanride” (in any case or form --indicated by the [NC] flag-- except for “ICANRide”) and if it does, redirect to ICANRide/<whatever>

You need the first rule to prevent an infinite loop

icanride -> (hey that matches) -> ICANRide -> (hey that matches) -> ICANRide -> (hey that matches) -> ICANRide -> (hey that matches) -> ICANRide -> (hey that matches) -> ICANRide -> (hey that matches) -> ICANRide -> (hey that matches) -> …

ah, thanks. that stuff is still voodoo to me.

well, it’s still not quite working, this fails:

Oops, that slash should be optional. And you do have RewriteEngine On somewhere in your .htaccess don’t you?

RewriteEngine On
RewriteRule ^ICANRide - [S=1]
RewriteRule ^icanride(/?.*)$ /ICANRide$1 [L,R=301,NC]

(just tested it here, works fine :))

that’s weird, because I get a 404 when trying something like: or

and yes, rewrite is on

Are you on Apache 1.x?

If so, try

RewriteEngine On
RewriteRule ^/ICANRide - [S=1]
RewriteRule ^/icanride(/?.*)$ /ICANRide$1 [L,R=301,NC]

I’m totally stumped, still a 404. I wonder if some of the other rewrite stuff is messing with this? it is a Joomla site by the way.

You need to put these rules ~above~ all the joomla stuff. If you it below it won’t work.

If you can’t get it to work if you put it above those rules, can you post the complete .htaccess please?

Moving it above worked. Now to test the Joomla site and make sure it’s still ok with this in it. Thanks much ScallioXTX!