Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Let's say I keep every word of file names capitalized. For example, Home.php or MultipleWordTitle.html.

Is there any way for Apache to redirect requests for incorrectly-cased URLs to the capitalized pages, preferrably using .htaccess?

Simply rewriting the URL to make the first letter capitalized won't work, since some files have multiple capital letters.

Ideally, I'd like the change to be reflected on the user's side, so it would show up as MultipleWordTitle.html in his/her address bar. It's okay if that can't be done, though.

share|improve this question
    
Yes, it should be possible (although very non typical/unusual task), but it will require 2 lines for each file in question -- it is simply not-practical to do via .htaccess (especially if you have a lot of such rules). Much better approach will be to do it on script level (PHP/ASP.NET etc): when page is requested you generate URL how it should be and compare to what you have. If they do not match -- issue 301 Permanent Redirect to a proper URL. –  LazyOne Aug 19 '11 at 0:16
add comment

1 Answer

up vote 4 down vote accepted

There are many reasons not to ignore the all-lowercase convention but, if you believe you have a good reason for doing so, you can use Apache's mod_speling to ignore case problems in the request and then specify the canonical URL in the document itself, or issue a redirect as LazyOne described.

share|improve this answer
    
Thanks for the tip. I have decided to just stick with the convention and use all-lowercase file names, but it's good to know that this can be done if needed. –  Maxpm Aug 19 '11 at 9:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.