Forum Moderators: phranque

Message Too Old, No Replies

Uppercase to lowercase

.htaccess code

         

vfetty

7:01 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Hello, I am trying to get

http://www.example.com/FORUM
to
http://www.example.com/forum

http://www.example.com/FORUM gives me a 404 error and I need it to go to http://www.example.com/forum instead, need this code to work in my .htaccess file.

Few things I tried
RewriteMap lowercase int:tolower
redirectMatch 301 {lowercase:^(.*)$ http://www.example.com$1

the above does not work in htaccess files, anything I can do just for that one example?

Thanks!

jdMorgan

8:01 pm on Jan 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RedirectMatch is not a mod_rewrite directive; It belongs to mod_alias. So the first thing to do is to look up the RewriteRule directive in the Apache mod_rewrite documentation.

Also, be aware that although you can use a rewritemap in .htaccess, you cannot define one there using RewriteMap; Maps must be defined in httpd.conf or one of the server-level config files. If you do not have access to the server config files, then you'll be stuck with an inefficient character-by-character replacement solution. If that is the case, be sure to put the code as close to the start of your .htaccess file as possible, because you will end up re-running the entire file for each uppercase character in the requested URL.

There are some threads around here that show how to replace the characters one at a time, deferring the external redirect until all are replaced. Try searching this forum for "uppercase lowercase rewriterule" and similar.

Jim

vfetty

8:32 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Ok I can get to the etc/httpd.conf file but where do I put it?

rewriteEngine on
rewriteMap lowercase int:tolower
rewriteCond $1 [A-Z]
rewriteRule ^/(.*)$ /${lowercase:$1} [R=301,L]

and is the above correct for any directory on my site?

jdMorgan

1:36 am on Jan 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Only the RewriteMap needs to be declared in http.conf -- The rest can go in .htaccess

Jim

vfetty

4:22 am on Jan 9, 2008 (gmt 0)

10+ Year Member



Oh ok but still where does rewriteMap go in the httpd.conf file? There is no defined place for it.

jdMorgan

5:12 am on Jan 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The answer depends on your current server configuration and what you want to do, so no one but you can answer this question.

Generally, place it inside the <container> directive in which you want it to apply, be that <VirtualHost>, <Directory>, etc.

Jim

vfetty

1:30 pm on Jan 9, 2008 (gmt 0)

10+ Year Member



Spoken like a true apache guy, lol! So since I have no idea I will humbly ask if I want it to be global for any of my domains what container would I put it in. My httpd.conf file is pretty simple and full of comments more then actual directives. Thanks:)

jdMorgan

5:18 pm on Jan 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, that's just how Apache is. It is not simple and straightforward. Except for 'toy' server installations and load-shared 'mirror' servers, I don't think I've ever seen two working Apache servers configured alike!

What you need depends on what you want, and we cannot tell you what you want.

I would suggest that you experiment a bit -- It's not likely that you will hurt anything if you place the code inside a "small" container at first, and then work up to more "global" containers, testing as you go.

We can "advise" and "help" here, but it's your server and your site(s) -- So it's up to you to do the real work -- and then test it until you're satisfied that it's perfect. :)

Jim

vfetty

5:27 pm on Jan 9, 2008 (gmt 0)

10+ Year Member



That is sounds like a plan and I appreciate the help, really:) The container to start with, is there such a container for per domain?

coopster

8:10 pm on Jan 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The containers mentioned by jdMorgan earlier are listed there, vfetty. Yes, the Apache Configuration Sections [httpd.apache.org] have one specifically for domains -- they are the <VirtualHost> [httpd.apache.org] containers.

vfetty

8:19 pm on Jan 10, 2008 (gmt 0)

10+ Year Member



Thanks coopster for you time and answer:) I really want to thank everyone that helped. I was given some good advice and it was, read the book. Not really much of a reader but I work really good with examples, it's how my brain works:) Though I am going to try before posting in the apache section again. Then maybe I can teach you all a thing or two, lol!