Web Hosting Forum | Lunarpages

Author Topic: How To Make URL's not case sensitive  (Read 21311 times)

Offline JamesG

  • Web Designer UK
  • Berserker Poster
  • *****
  • Posts: 11732
  • Web Designer
    • Affordable Web Design
How To Make URL's not case sensitive
« on: December 08, 2004, 09:18:05 AM »
this was made by Nibbler, one of the PHP experts that lurks the Lunarpages forums... if you think this is good, you could visit his site, and give him your appreciation: http://coppermine.sourceforge.net/

as you know Lunarpages server are case sensitive which means if you had a page located at http://yourdomain.com/FILES/index.html and somebody typed in the browser http://yourdomain.com/files/index.html they would get a 404 error rather than the page you want them to see.

but if you add this into a .htaccess file and put it in your root directory (or public_html)

Code: [Select]
ErrorDocument 404 /404.php

and in the same folder put a file names 404.php containg the following

Code: [Select]
<?php
$lower 
strtolower&#40;$_SERVER['REQUEST_URI'&#93;&#41;;
$new 'http&#58;//' $_SERVER['HTTP_HOST'&#93; . $lower;

if &#40;file_exists&#40;ltrim&#40;$lower, '/'&#41;&#41; && $_SERVER['PHP_SELF'&#93; != $lower&#41;&#123;
header&#40;"Location&#58; $new"&#41;;
exit;
&
#125; else &#123;
echo 'Page not found';
&
#125;
?>


when someone types the correct URL, but in the wrong case, they will go to the correct page....

Thanks Nibbler

Offline checkup

  • Spacescooter Operator
  • *****
  • Posts: 38
How To Make URL's not case sensitive
« Reply #1 on: December 08, 2004, 09:52:06 PM »
This is useful. :thumb:

Seems to work for main page, but did not work for this case:

Page on web site is: TrialBSCbscr.htm


I typed in: http://www.mysite.lunarpages.com/trialbscr.htm
but got the Page not found message.

How can I extend the code to handle this?

(and also how could I include a home page link on the Page not found message?)

I'm new to php :oops:

Offline JamesG

  • Web Designer UK
  • Berserker Poster
  • *****
  • Posts: 11732
  • Web Designer
    • Affordable Web Design
How To Make URL's not case sensitive
« Reply #2 on: December 09, 2004, 01:28:16 AM »
where it says "Page Not Found" change that to what you want the page not found page to say :thumb:

there is an option in CPanel to customize your error pages!
« Last Edit: June 17, 2006, 07:53:22 AM by JamesG »

Offline Nibbler

  • 21st century digital boy
  • Master Jedi
  • *****
  • Posts: 1168
    • Coppermine
How To Make URL's not case sensitive
« Reply #3 on: December 09, 2004, 04:20:20 AM »
There is no way to handle that unless you want to try all possible combinations of capitalisation, which would just be silleh.
Missing since 1983


Offline JamesG

  • Web Designer UK
  • Berserker Poster
  • *****
  • Posts: 11732
  • Web Designer
    • Affordable Web Design
How To Make URL's not case sensitive
« Reply #4 on: December 09, 2004, 04:44:35 AM »
i cant see many people going to a website and typing:

www.DoMaIn.CoM/DiR/InDeX.PhP

Lupine1647

  • Guest
How To Make URL's not case sensitive
« Reply #5 on: December 09, 2004, 01:46:09 PM »
I get some hits from people who forget to turn off caps lock, and you get INDEX.PHP

Offline JamesG

  • Web Designer UK
  • Berserker Poster
  • *****
  • Posts: 11732
  • Web Designer
    • Affordable Web Design
How To Make URL's not case sensitive
« Reply #6 on: December 09, 2004, 04:40:40 PM »
but that would work with this script...

Lupine1647

  • Guest
How To Make URL's not case sensitive
« Reply #7 on: December 09, 2004, 05:49:00 PM »
Quote from: Garvey
but that would work with this script...


yea, but I thought you were talking about why would people want to use this script. (Ok, I'm sick today so I cn't think  :sleep: )

Offline JamesG

  • Web Designer UK
  • Berserker Poster
  • *****
  • Posts: 11732
  • Web Designer
    • Affordable Web Design
How To Make URL's not case sensitive
« Reply #8 on: December 10, 2004, 01:33:51 AM »
you need some alcohol

Offline PeterJames

  • Space Explorer
  • ***
  • Posts: 6
    • http://peter-thomson.com
How To Make URL's not case sensitive
« Reply #9 on: June 03, 2005, 01:49:09 PM »
Quote from: checkup
This is useful. :thumb:

Seems to work for main page, but did not work for this case:

Page on web site is: TrialBSCbscr.htm


 I have worked out a system that will always redirect the url typed in to the best match. - and will work for your case

So /TeSt_ThIs would be directed to Test_this, or to TEST_THIS or whichever is on your site.

Truncated urls will also be redirected to the nearest match.

so /thishouldbeapage  is redirected to /thishouldbeapage.html

Test it on my site by altering any URL capitalisation to see what you get.
http://www.peter-thomson.co.uk

You can download this from the Perl area of my site:
http://www.peter-thomson.co.uk/perl/index.html
Peter

Offline Marce_22

  • Intergalactic Superstar
  • *****
  • Posts: 197
    • http://www.magnonic.com
How To Make URL's not case sensitive
« Reply #10 on: June 08, 2005, 03:27:52 PM »
Thanks for the link, Peter!

However, I do find it some-what annoying and pointless that I have to "register" to access the download. I'm not quite too sure why you have it like this, especially since you can just put any giberish you want in the fields and you can still access the downloads... Either way, good work and thanks!
Surfing the Net at work? Don't get caught! Download Instant Hidden Internet.

Need a good color picker for web design? Try Bullseye Color Picker.

Visit MAGNONIC SOFTWARE for more programs.

Offline DiFFereNT

  • Newbie
  • *
  • Posts: 1
Re: How To Make URL's not case sensitive
« Reply #11 on: February 09, 2006, 12:16:41 PM »
I realize this discussion is old, but thanks to Google I just found it.

For some reasons, I am not able to get Peter's PHP/Perl scripts to work.
Instead, I receive an Internal Server Error 500 when trying to access any path with the incorrect case.
===========================================================
And if it helps, here is the URL it displays in the address bar when I get the 500:

http://www.domain.com/cgi-bin/error.pl?request=http://www.domain.com/photos/BillGates/Google/
Of course, the last URL is what I typed. The actual folder names are:
http://www.domain.com/PHOTOS/BillGates/Google
============================================================
And here is the error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@domain.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
============================================================
Help would be greatly appreciated.

Thanks
« Last Edit: February 09, 2006, 12:22:23 PM by DiFFereNT »

Offline cemedia

  • Intergalactic Superstar
  • *****
  • Posts: 152
    • Criminal Existence
Re: How To Make URL's not case sensitive
« Reply #12 on: August 18, 2006, 09:19:15 AM »
Stepping back to the first post (topic starter)

you know that this is a great feature that the LP servers are case sensitive

lets say you have a admin.php at /admin like most sites

if the folder is /ADMIN you will have less people who will try to get access as /admin will give them a error page, 99% will never try /ADMIN


Offline Mike Good

  • Newbie
  • *
  • Posts: 2
Re: How To Make URL's not case sensitive
« Reply #13 on: August 22, 2006, 09:42:25 AM »
I Know this is old but, I found it pretty helpful. I run a directory website and people type in wrong things all the time. Thanks for the link and Thread. See you around.

Offline JamesG

  • Web Designer UK
  • Berserker Poster
  • *****
  • Posts: 11732
  • Web Designer
    • Affordable Web Design
Re: How To Make URL's not case sensitive
« Reply #14 on: August 22, 2006, 09:44:48 AM »
glad it helped :-)

 

Share |