Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can I use Apache htaccess to handle case sensitive file names on a website?

Posted on 2010-08-15
27
Medium Priority
?
1,634 Views
Last Modified: 2012-05-10
I have a client who just moved to a new server and has a ton of file names with various capitalization.  It's a Linux server, so "INDEX.php" and "index.php" are not the same.  I did some research and found I could use .htaccess to rewrite URLs to lowercase.  Bingo!  Here's the current version of what I'm trying:

RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

That code results in a 500 server configuration error.  I have read that I also need to change something in httpd.conf, but the documentation on the Apache site is not making sense to me.  Can this all be done just in .htaccess?  If not, exactly what do I need to do in her httpd.conf?  I hate to seem like I'm asking experts to do the work for me, but I'm under a deadline and I learn best by seeing a working example and reverse engineering it in my brain.

I'm really hoping to get this rolling so she won't need to change possibly hundreds of file names.  I have, however, told her and her staff to be sure to use all lowercase file names from now on.

Thanks in advance!

Jeremy
0
Comment
Question by:mrcoulson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 16
  • 11
27 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 33442568
If you put "CheckSpelling On" in your 'htaccess', it will ignore case in the files names.  And then you don't need the re-write.  At least it worked for me.
0
 

Author Comment

by:mrcoulson
ID: 33442569
For real?  I'm trying that now!

Jeremy
0
 

Author Comment

by:mrcoulson
ID: 33442572
Bummer!  Ye olde internal server error returns with that one.

Jeremy
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442576
Did you remove the 'rewrite' code?
0
 

Author Comment

by:mrcoulson
ID: 33442580
Yep.  Well, I commented it away.

# RewriteEngine On
# RewriteMap lc int:tolower
# RewriteCond %{REQUEST_URI} [A-Z]
# RewriteRule (.*) ${lc:$1} [R=301,L]
CheckSpelling On

Jeremy
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442590
What did you do to get the error?  Can you access a simple HTML file without error?  Remove the 'htaccess' completely and recheck?  I'm trying to establish what does work.  Something must...
0
 

Author Comment

by:mrcoulson
ID: 33442601
If I comment those lines out of the .htaccess or rename it to something else, I can access a simple HTML file.  If I leave them uncommented or do not rename the .htaccess file, I get the 500 error.

Jeremy
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442611
What hosting or server are you on?  What happens if 'htaccess' only has 'CheckSpelling On' and nothing else?  What if it only has '#' in it?
0
 

Author Comment

by:mrcoulson
ID: 33442617
The hosting company is Verio.

Just "CheckSpelling On" gives 500 error.

Just a "#" character gives no error.

Jeremy
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442651
They say they're running Red Hat Enterprise Linux (RHEL).  I can't find anything that says whether they support 'htaccess' or not.  You may need to call them and ask.  Try "ErrorDocument 400 /400.html" in 'htaccess'.  Pretty much your most basic 'htaccess' command.
0
 

Author Comment

by:mrcoulson
ID: 33442652
Yeah, that works.  I was playing with it earlier.

Jeremy
0
 

Author Comment

by:mrcoulson
ID: 33442655
Also, they already told me they can't help me with the .htaccess file.

Jeremy
0
 

Author Comment

by:mrcoulson
ID: 33442658
I found this inside the httpd.conf.

 <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteOptions inherit
    </IfModule>

Jeremy
0
 

Author Comment

by:mrcoulson
ID: 33442660
How about an error?  Here's what I found for when I tried "CheckSpelling":

[Sun Aug 15 21:01:04 2010] [alert] [client 71.62.239.244] /path/www/stuff/.htaccess: Invalid command 'CheckSpelling', perhaps mis-spelled or defined by a module not included in the server configuration

Jeremy
0
 

Author Comment

by:mrcoulson
ID: 33442667
Oh, and when I use rewritemap, I get that "RewriteMap not allowed here"

Jeremy
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442680
Here's the Apache page on the subject.  'CheckSpelling' is include but not necessarily loaded.  "CheckCaseOnly on" is another option.  
http://httpd.apache.org/docs/current/mod/mod_speling.html.en

Look for:

LoadModule speling_module modules/mod_speling.so

in httpd.conf.
0
 

Author Comment

by:mrcoulson
ID: 33442713
I found it!  I uncommented it!  Nothing changed.  Do I need to restart Apache for config changes to take effect?

Jeremy
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442731
Yes, restart Apache any time you change httpd.conf or any of the conf files.
0
 

Author Comment

by:mrcoulson
ID: 33442741
GOT IT!

Had to do this as root.  Found the module in httpd.conf.  Uncommented.  Restarted httpd.  Added "CheckSpelling On" to .htaccess.  "INDEX.php" now goes right for "index.php".  Beautiful.  Thank you so much.  500 points coming your way.

By the way, any "gotchas" I should be aware of with this?

Jeremy
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442746
There is one in the documentation.  It will do a one-character spelling correction which you may or may not want.  That's why I noted the  "CheckCaseOnly on" option which only affect capitalization.
0
 

Author Comment

by:mrcoulson
ID: 33442797
Ah, I see.  When I try to use CheckCaseOnly, I get the 500 error.  I see it's part of the same module.  Did I miss something?

Jeremy
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442813
Apparently it's on for Apache 2.2.  See if you have 2.0 or 1.3.
0
 

Author Comment

by:mrcoulson
ID: 33442820
2.0.63

Jeremy
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442844
You'll have to use "CheckSpelling On" then.  It's been working for me on two websites.
0
 

Author Comment

by:mrcoulson
ID: 33442906
Sounds good.  Really appreciate your assistance!

Jeremy
0
 

Author Closing Comment

by:mrcoulson
ID: 33442910
Thanks for all the help, man!
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 33442926
You're welcome and thanks for the points.  Your points just helped put me over 1,000,000 points.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question