Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Website and Server Administration Forum


You are currently viewing our Website and Server Administration Forum as a guest. Please register to participate.
Login



Reply
How to ignore capitalization in .htaccess redirects?
Old 06-21-2011, 12:34 PM How to ignore capitalization in .htaccess redirects?
Super Talker

Posts: 113
Trades: 0
I'm redirecting a bunch of directories on my site using statements like:

Code:
Redirect /olddirectory http://www.mywebsite.com/newdirectory
The problem is that if a user capitalizes a letter, or the entire directory name, then the redirect doesn't work. I don't think many people would type the directory name in anything other than lowercase, but in the off-chance that someone does, how can I get the redirect to work regardless of the capitalization?
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-21-2011, 01:34 PM Re: How to ignore capitalization in .htaccess redirects?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,380
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Just as long as you get a 404 response code, don't worry about it.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-21-2011, 02:33 PM Re: How to ignore capitalization in .htaccess redirects?
Super Talker

Posts: 113
Trades: 0
Is there no way to overcome the problem, other than having multiple redirects like this?:

Code:
Redirect /olddirectory http://www.mywebsite.com/newdirectory
Redirect /oldDirectory http://www.mywebsite.com/newdirectory
Redirect /OldDirectory http://www.mywebsite.com/newdirectory
Redirect /OLDDIRECTORY http://www.mywebsite.com/newdirectory
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 06-21-2011, 02:48 PM Re: How to ignore capitalization in .htaccess redirects?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,380
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Don't even THINK about that!!!!! each line of the .htaccess file has to be read for EVERY request made to the server. So a THREE letter name creates EIGHT lines. (WordLength^2)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-29-2011, 10:58 AM Re: How to ignore capitalization in .htaccess redirects?
Super Talker

Posts: 113
Trades: 0
Well, I don't need to have every case in the .htaccess file, just lowercase, uppercase, first letter capitalized, and the first letter of each word capitalized. So that would be four lines for each case.

The thing is, I'm trying to do this for what's sort of a 'turnkey' website, so I really need to make sure if the person's url is typed in the wrong case that the user stays on their site..
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 06-29-2011, 11:30 AM Re: How to ignore capitalization in .htaccess redirects?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,380
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
So four lines for each case, if you only have ten pages, that's forty lines to be processed for each request

AND that's what the "404" error handling page is for, catching mispelt page manes.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-29-2011, 11:52 AM Re: How to ignore capitalization in .htaccess redirects?
Super Talker

Posts: 113
Trades: 0
Is it bad to have a lot of lines in the .htacces file? What alternative is there for me if I end up having dozens of redirects needed (not including capitalization cases)?

Are you suggesting that I make the 404 page PHP and try to redirect the user to the correct page?
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 06-29-2011, 12:12 PM Re: How to ignore capitalization in .htaccess redirects?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,380
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Is it bad to have a lot of lines in the .htacces file?
It can be.


Unless you are using RedirectMatch conditionals, every line has to executed and evaluated against the current request, twice if a redirect is triggered.

It all adds overhead to the request.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-03-2011, 05:52 PM Re: How to ignore capitalization in .htaccess redirects?
L a r r y's Avatar
Super Talker

Posts: 103
Name: Larry K
Location: Arizona
Trades: 0
Apache doesn't recommend using .htaccess, if you can avoid it, for it causes a performance hit: The server must load the .htaccess file with every request, and if/deep/in/a/tree/, it must look in every level up the tree for one whether it exists or not. If you can place your redirects in the server httpd.conf file, that gets read once and won't be nearly as bad. However, many of us use shared hosting and do not have that option.

Perhaps another approach would be to design a 404 page at the destination site to use php or cgi code to catch DirectoryNames that contain caps and send them on to their lowercase counterparts.

At least then an action is taken only when needed and you don't burden the entire system to cover a "what-if."

Hope this helps.....
__________________
Larry
Please login or register to view this content. Registration is FREE
L a r r y is offline
Reply With Quote
View Public Profile Visit L a r r y's homepage!
 
Old 07-04-2011, 11:06 AM Re: How to ignore capitalization in .htaccess redirects?
Super Talker

Posts: 113
Trades: 0
Quote:
Originally Posted by L a r r y View Post
Perhaps another approach would be to design a 404 page at the destination site to use php or cgi code to catch DirectoryNames that contain caps and send them on to their lowercase counterparts.

At least then an action is taken only when needed and you don't burden the entire system to cover a "what-if."

Hope this helps.....
I could do that. I had no idea that having many lines in the .htaccess file was a bad thing

However, doing as you suggest might mean not having a sitemap as my 404 page. Would this hurt my site's seo?
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 07-04-2011, 01:52 PM Re: How to ignore capitalization in .htaccess redirects?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,380
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
However, doing as you suggest might mean not having a sitemap as my 404 page. Would this hurt my site's seo?
Why would it?

You are not changing anything on the pages.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-24-2011, 09:02 PM Re: How to ignore capitalization in .htaccess redirects?
L a r r y's Avatar
Super Talker

Posts: 103
Name: Larry K
Location: Arizona
Trades: 0
Quote:
Originally Posted by Learnin' n00b View Post
I could do that. I had no idea that having many lines in the .htaccess file was a bad thing

However, doing as you suggest might mean not having a sitemap as my 404 page. Would this hurt my site's seo?
Your 404 page, if written in php, for instance, can be written to include some form of logic that consists of an "if - then - else." Something on the order of:

IF

a CapitalizedFilename is sent to 404 because it doesn't exist, THEN
I have a routine here to make it all lowercase and forward it on."

ELSE

Generate the HTML containing the standard output of your 404 page, which can contain a link to your sitemap or can be a sitemap.

END IF

Now, I am recalling syntax from BASIC in this example, as I used a lot of that on my Radio Shack Color Computer 2, 30 years ago. But PHP and Perl, even Bash, have their own syntax for accomplishing this same thing.

And if a CapitalLink is 404'd it runs through the routine and gets sent out in lowercase, and then, if that doesn't exist, it will be 404'd again. This time the 404 Not Found page/sitemap is displayed on the visitor's screen.

There is a http://tycoontalk.freelancer.com/web...4-rewrite.html rewrite thread that may be of interest to you in designing logic into a 404 page.
__________________
Larry
Please login or register to view this content. Registration is FREE

Last edited by L a r r y; 07-24-2011 at 09:04 PM.. Reason: typo
L a r r y is offline
Reply With Quote
View Public Profile Visit L a r r y's homepage!
 
Reply     « Reply to How to ignore capitalization in .htaccess redirects?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.41441 seconds with 12 queries