We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4018
    • 1,131 Posts
    Another fix related to Google Sitemaps. Apparently, there’s a problem with the 404 error page returning a status of 200. So...I noticed that someone had the same problem on the Etomite site. The trick is to add the 404 to the header just before the redirect. Changing the sendErrorPage function in document.parser.class.inc.php file does the trick I think:

    Around line 115:

    	function sendErrorPage() {
    		// invoke OnPageNotFound event
    		$this->invokeEvent('OnPageNotFound');
    		$this->sendRedirect($this->makeUrl($this->config['error_page'],'','&refurl='.urlencode($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'])), 1);
    	}
    


    Change to:

    	function sendErrorPage() {
    		// invoke OnPageNotFound event
    		$this->invokeEvent('OnPageNotFound');
    		header("HTTP/1.0 404 Not Found");
    		$this->sendRedirect($this->makeUrl($this->config['error_page'],'','&refurl='.urlencode($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'])), 1);
    	}
    


    That’s all I have for now...

    Jeff
      Jeff Whitfield

      "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
      • 25663 MODX Staff
      • 12,272 Posts
      Jeff, will that 404 fix help with the Apache Error logs when SEF URLs is on also? If so, we’ve solved a nice little problem that some folks are struggling with in that respect.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 4018
        • 1,131 Posts
        I think so...not sure really. There’s more on this topic on the Etomite forums (here.

        I’ll have to investigate the whole 302 thing with Apache. My best guess is that it has something to do with the mod_rewrite module.
          Jeff Whitfield

          "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
          • 31337
          • 258 Posts
          Quote from: rthrash at Oct 06, 2005, 06:32 PM

          Jeff, will that 404 fix help with the Apache Error logs when SEF URLs is on also? If so, we’ve solved a nice little problem that some folks are struggling with in that respect.

          This does not address the issue with SEF URLs completely. The way we currently manage those is to create a mod_rewrite rule that looks at any URL that’s requested that doesn’s exist as a physical file, and send a 302 redirect to the index page with that page as a parameter. The problem is that this redirect has zero knowledge of whether what’s been requested is a real page or not. Thus a request for a real page gets you redirected there, but a request for a non-existent page is passed as a redirect just the same.

          So this fix will help modx with logging of error pages, but for those of us who like to use our Apache logs, it doesn’t do much unfortunately.
            • 25663 MODX Staff
            • 12,272 Posts
            So, this then begs the question of can we have our cake and eat it too: Are SEF URLs via mod_rewrite mutually exclusive with complete Apache logging?

            We might consider looking at how SMF handles rewrites, because they do not rely on .htaccess files to do rewriting of URLs.

            Any other ideas?
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 25663 MODX Staff
              • 12,272 Posts
              I take that back, they do use .htaccess, but don’t use mod_rewrite (I think). SMF’s entire .htaccess file looks like:

              AcceptPathInfo On
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 4018
                • 1,131 Posts
                Yeah, from what I’ve read there’s no easy answer for 302 logs in Apache for mod_rewrite. This fix does address the problem of error pages being marked as a 302 instead of a 404. However, the fix I presented isn’t 100% complete. I did a little more investigating and found out that you almost have to explicitly define a 404 before redirecting to the actual error page. So, I felt perhaps a modest change to the sendRedirect function was in order in the document.parser.class.inc.php file. Here’s what I’ve done:

                Around line 101:

                			if($type==REDIRECT_REFRESH) {
                				$header = 'Refresh: 0;URL='.$url;
                			} elseif($type==REDIRECT_META) {
                				$header = '<META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$url.'" />';
                				echo $header;
                				exit;
                			} elseif($type==REDIRECT_HEADER || empty($type)) {
                				$header = 'Location: '.$url;
                			}
                			header($header);
                


                Replace with:

                			if($type==REDIRECT_REFRESH) {
                				$header = 'Refresh: 0;URL='.$url;
                			} elseif($type==REDIRECT_META) {
                				$header = '<META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$url.'" />';
                				echo $header;
                				exit;
                			} elseif($type==REDIRECT_ERROR) {
                				header("HTTP/1.0 404 Not Found");
                				header("Refresh: 0; URL=".$url, 0);
                				exit;
                			} elseif($type==REDIRECT_HEADER || empty($type)) {
                				$header = 'Location: '.$url;
                			}
                			header($header);
                


                Basically, I added a REDIRECT_ERROR type that forces a 404 into the header then redirects to the error page. Now all we need to do is change the call to the function to include the error type like so:

                Around line 119:

                	function sendErrorPage() {
                		// invoke OnPageNotFound event
                		$this->invokeEvent('OnPageNotFound');
                		$this->sendRedirect($this->makeUrl($this->config['error_page'],'','&refurl='.urlencode($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'])), 1);
                	}
                


                Change to:

                	function sendErrorPage() {
                		// invoke OnPageNotFound event
                		$this->invokeEvent('OnPageNotFound');
                		$this->sendRedirect($this->makeUrl($this->config['error_page'],'','&refurl='.urlencode($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'])), 1,REDIRECT_ERROR);
                	}
                


                Make these changes then attempt to visit a page that doesn’t exist. You’ll still be redirected to your error page and the error page itself will still have a 200 OK header...but look at the Apache logs. When the attempt is made to visit the non-existent page, Apache will log it properly with a 404 now. Without this change, Apache will label it as a 302 redirect.
                  Jeff Whitfield

                  "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
                  • 32963
                  • 1,732 Posts
                  Hi Jeff,

                  I’m afraid that this solution is causing. IE to display a 404 page. I’m using IIS with FriendlyURL

                    xWisdom
                    www.xwisdomhtml.com
                    The fear of the Lord is the beginning of wisdom:
                    MODx Co-Founder - Create and do more with less.
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Raymond, can you offer an alternate solution that will work with IIS... or can this be a configuration flag so that folks that actually can get FURLs working on IIS don’t get an error. The 404 handling needs to be udpated in a big way.
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 33337
                      • 3,975 Posts
                      I like the SMF way to adopt SEF urls, is it possible to have in MODx !

                      Just my 2 cents :-|
                        Zaigham R - MODX Professional | Skype | Email | Twitter

                        Digging the interwebs for #MODX gems and bringing it to you. modx.link