SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    May 2007
    Location
    West Coast
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Any Concern with 500 Server errors?

    I got a spike in Google Webmaster 500 server errors on the 19th and it is going up.

    I changed the url structure of the pages from site com/innerpage/ to site com/innerpage

    Initially, it was site com/innerpage with a folder called "innerpage" that had an index.php file which pulled content from content > innerpage.php

    Now it is site com/innerpage.php and the updated htaccess removes the .php extension

    Code:
    ErrorDocument 404 http://www.site.com/404
    
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [NC,L]
    
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^site.com
    RewriteRule (.*) http://www.site.com/$1 [R=301,L]
    4.) If those older site.com/innerpage/ are typed in the address bar, it does not go to 404 page, it goes to Server error 500.
    other mistypes do go to 404 error page

    There are no links to these older page formats but Google webmaster tools is increasing with these 500 errors.


    Should I be concerned?

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,072
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    What errors are showing in Apache's error log?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    lukkas,

    First, follow SP's suggestion and look at the errors to see what is wrong.

    From my experience, 500 errors, though, are caused by ILLEGAL code in the .htaccess file. Okay, illegal is overboard. It's simply code which is typographically or syntactically incorrect ... and can bring an entire website down!

    The code you show has the following errors:

    Code:
    ErrorDocument 404 http://www.site.com/404
    # Error Document REQUIRES an absolute link so this should be some form of /.404.php
    # I believe that the following code will handle your /404, though, but you should know how to do it correctly.
    
    RewriteEngine on
    RewriteBase /
    # NOT necessary in the DocumentRoot and can cause directory level problems
    # albeit it does not seem to be the case here
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}.php -f
    # Both of those are good but ...
    RewriteRule ^(.*)$ $1.php [NC,L]
    
    # MAJOR PROBLEMS:
    #
    # 1. The (.*) lazy code matches everything or nothing. THINK! What does it do for your /innerpage/?
    #     It will redirect to /innerpage/.php, of course! I'm sure that you do NOT have nameless files
    #     with .php extension lying around to collect these ridiculous links so you MUST protect against
    #     the trailing / on files (best to 301 them to real links then add the .php file extension).
    #     My advice is to use ([a-z]+) (for DirectoryRoot filenames) and not the lazy code.
    #     My standard rant about this will follow.
    #
    # 2. The No Case flag has no business in a RewriteRule flag set because URIs ARE case sensitive!
    #     Okay, this is not the 500 generator but it IS a 404 generator for you!
    
    RewriteEngine on 
    # Didn't you already take mod_rewrite out of "Comment Mode" above? 
    # "Don't repeat yourself repetitively."
    
    RewriteCond %{HTTP_HOST} ^site.com
    # You've forgotten the \ before the dot metacharacter AND
    # the No Case flag (because domain names are NOT case sensitive
    
    RewriteRule (.*) http://www.site.com/$1 [R=301,L]
    # I'm loathe to admit that (.*) is what you want here although you should use the Apache variable
    # RewriteRule .? http://www.site.com%{REQUEST_URI} [R=301,L]
    As promised, my Standard Rant # 1:

    [rant #1]
    The use of "lazy regex," specifically the EVERYTHING atom, (.*), and its close relatives, is the NUMBER ONE coding error of newbies BECAUSE it is "greedy." Unless you provide an "exit" from your redirection, you will ALWAYS end up in a loop!
    [/rant #1]

    Indeed, you MUST be concerned over code which is causing server errors, infinite loops, etc. It's another case of knowing what your code is doing before you use it online! You just don't want the tarnished reputation that they give you.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Addict
    Join Date
    May 2007
    Location
    West Coast
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your suggestion to replace the lazy " .* is " ([a-z]+)" - do you mean " ([a-z,A-Z,0-9]+)/([a-z,A-Z,0-9]+)/([0-9]+) " in its place ?

    I know intermediate CSS and html, not programming so much. I was just looking for some quick help but you found other errors which could help.

    I surely don't want loops or bad code either because a correction is needed so I can rebuild another larger site.

    This is a whole new site structure for me building (trying) with php.

    I almost had a 2nd problem from the error log for you but I just fixed. And yes, I get more satisfaction from finding/solving it myself but some things are just over my head.

    Sometimes, it is like bringing a musician into the middle of a discounted cash flow analysis course, yet I am neither.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    lukkas,

    Quote Originally Posted by lukkas View Post
    Your suggestion to replace the lazy " .* is " ([a-z]+)" - do you mean " ([a-z,A-Z,0-9]+)/([a-z,A-Z,0-9]+)/([0-9]+) " in its place ?

    Horrors, no! Most people only use lowercase letters in filenames so my recommendation of "([a-z]+)" meant to replace "(.*)" with just that. What's wrong with your suggestion? First, I believe , is a reserved character so it really shouldn't appear even once in your character range definitions. Second, you're REALLY using a three tiered directory structure? It's okay if you are but that was not expected. If you are, you can use "([a-z/]+)+ and that should do it (again, though, only for lower case letters.

    Need the dot character, too? Just pop it into the character range definition (it's NOT a metacharacter there).

    Need uppercase characters? REALLY? Okay, change "[a-z]" to "[a-zA-Z]" (and leave the + in place as it requires one or more of the preceding character [in this case, set of characters]).

    Need digits, too? OMG! Okay, add "0-9" within the character range definition, too.

    IN ALL MY ABOVE EXAMPLES, DO NOT INCLUDE THE QUOTES!

    Sometimes, it is like bringing a musician into the middle of a discounted cash flow analysis course, yet I am neither.

    That's a good one! It's like pairing a fish with a bicycle.
    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •