URL's not defaulting to lower case

This is sort of a continuation of this thread, except that I gave up on ever finding the httpd.conf file on my computer. I did manage to access my ONLINE httpd.conf file and modify it, adding this code:


RewriteMap tolower int:tolower

I then restarted my server. Next, I modified an .htaccess file, adding this code:


RewriteMap lc int:tolower
RewriteRule (.*?[A-Z]+.*) ${lc:$1} [R]

I then visited a webpage - MySite/Topics/This_Article - and got an Internal Server Error message. (I verified that it was working before I published the .htaccess file.)

So I restored the .htaccess file, deleting the new code and publishing it online. Now I get a NOT FOUND error. In fact, it appears that ALL the child pages on the site are now dead. (The static pages - like MySite/Topics - still work.)

I tried the same experiment on another website with the same results. The modified .htaccess file gives me an Internal Server Error, and when I restore the .htaccess file, all the dynamically generated child pages display a Not Found error.

Maybe part of the problem is that I haven’t yet replace the URL’s with lower case URL’s in my database. So, if the URL’s or database are case sensitive, then the page might not display with capital letters OR lower case. However, it’s odd that none of my pages work, even after I restored the .htaccess files. Also, I thought the new code I added was supposed to make the URL’s change by default. In other words, if I type in MySite/Topics/This_Article, it should change to mysite/topics/this_article - whether there’s an article at that address or not. At least, that’s what I thought.

Below is a copy of my entire modified .htaccess file.

Thanks for any tips.


RewriteEngine On
RewriteRule ^test\\.htm$ test.php [L]
Options -MultiViews

# php_value magic_quotes_gpc 0
php_flag magic_quotes_gpc Off

RewriteMap lc int:tolower
RewriteRule (.*?[A-Z]+.*) ${lc:$1} [R]

ErrorDocument 404 /404.php
RewriteRule ^/([a-zA-Z0-9()_/-]+)/?$ index.php?home=$1 [L]
RewriteRule ^topics/([a-zA-Z0-9()_/-]+)/?$ topics/index.php?topic=$1 [L]
RewriteRule ^world/([a-zA-Z0-9()_/-]+)/?$ world/index.php?area=$1 [L]
RewriteRule ^people/([a-zA-Z0-9()_/-]+)/?$ people/index.php?ppl=$1 [L]
RewriteRule ^orgs/([a-zA-Z0-9()_/-]+)/?$ orgs/index.php?org=$1 [L]
RewriteRule ^essays/([a-zA-Z0-9()_/-]+)/?$ essays/index.php?ess=$1 [L]
RewriteRule ^exposes/([a-zA-Z0-9()_/-]+)/?$ exposes/index.php?exp=$1 [L]
RewriteRule ^revolt/([a-zA-Z0-9()_/-]+)/?$ revolt/index.php?rev=$1 [L]
RewriteRule ^glossary/([a-zA-Z0-9_/-]+)/?$ glossary/index.php?glos=$1 [L]
RewriteRule ^reference/([a-zA-Z0-9()_/-]+)/?$ reference/index.php?ref=$1 [L]
RewriteRule ^about/([a-zA-Z0-9_/-]+)/?$ about/index.php?about=$1 [L]

Maybe it’s named apache2.conf ? http://www.sitepoint.com/forums/showthread.php?1203573-Apache-Directory-Names-and-Images&p=5649332&viewfull=1#post5649332

Also, I added LogLevel trace8 to my httpd.conf file to help me troubleshoot the problem, but it killed all my websites; even the home pages wouldn’t display. Fortunately, I fixed it by restoring the httpd.conf file and restarting Apache.

Hmmm…Apache2.conf? Good tip. I didn’t find anything with a basic Mac search, but it could be one of those hidden files that you have to use Terminal to find.

On Edit: Wow, something you said led me in the right direction. It is named httpd.conf, and it’s in a very obvious directory - but it’s one of those secret directories Apple makes it difficult to discover.

The RewriteMap line should only exist in the server configuration, not in the htaccess.

Also, you need to be careful to keep the map name consistent.

RewriteMap ThisIsTheMapName int:tolower

The map name can be whatever you want it to be, provided that you use the same name when invoking it from a rewrite rule.

RewriteRule (.?[A-Z]+.) ${ThisIsTheMapName:$1} [R]

In the code I posted in the earlier thread, I used “tolower” as the map name, since it invokes the internal “tolower” function. The very similar code that your host gave you used “lc” as the map name, which is also fine since “lc” is a common abbreviation for lowercase. You can use whatever name you prefer, but you need to stay consistent with its usage.

Honestly, this doesn’t make a lot of sense. If you restored the exact same htaccess file that was up originally, then you should get the exact same result. My best educated guess is that when you went to delete the new code, something else got changed in some way. Or maybe when you edited the htaccess file the first time, perhaps it wasn’t an up to date copy?

That’s actually correct. Both URLs and database entries are case-sensitive unless you deliberately add functionality to make them case-insensitive.

The redirect flag [R] that you put in should do that, yes. Though, you may have to add a leading slash to the substitution when using the redirect flag.

RewriteRule (.?[A-Z]+.) /${lc:$1} [R]

Typically rewrite rules operate on relative directory paths, and the last step of a rewrite is to re-attach the directory prefix (which might be something like /var/www), and that directory prefix ends up getting included in your redirect. The leading slash in the substitution makes Apache instead treat it as a DocumentRoot-relative path.

Ah, now I understand a little better. I have this in my online httpd.conf file:

RewriteMap tolower int:tolower

So the map name is tolower.

I then went back and changed the new code in my .htaccess file to this…

RewriteRule (.*?[A-Z]+.*) ${tolower:$1} [R]

But when I click on a link to an article at MySite/Topics/This_Article, the link defaults to http://MySite/home/gd2/public_html/topics/this_article

That’s actually a step forward, because the link defaulted to lower case. I can’t really expect the page to display correctly because I haven’t put an article at topics/this-article yet; my online architecture is still set up for capital letters and underscores.

So it looks like it’s working! Except I don’t understand why it’s default to /gd2/public_html/. Do you think that’s simply a problem that will go away when I finish the job and have my database and includes set up to support lower case and dashes?

On Edit: One weird thing - when I delete the new code from my .htaccess file, the URL displays as it did before - MySite/Topics/This_Article. However, I do get a Not Found error. As near as I can determine, my .htaccess file is in its original state. I guess I should have made a back up copy, though.

That’s because rewrite rules operate on relative directory paths, and the last step of a rewrite is to re-attach the directory prefix (which in your case seems to be /gd2/public_html/). You should be able to solve that by adding a leading slash to the substitution (highlighted red below).

RewriteRule (.?[A-Z]+.) /${tolower:$1} [R]

You fixed it! It’s working really well now. Thanks.