📜 ⬆️ ⬇️

Your Joomla site incorrectly gives page 404

image

It is known that in order to keep a visitor on the site, you need to correctly handle HTTP / 1.0 404 and other similar codes. On the Internet you can find a lot of interesting examples of pages 404, as well as manuals - what and how to make the error 404 correctly processed by the site for both the visitor and the search engines.

I want to discuss problem 404 for Joomla sites with you.

General recommendations on how to configure Joomla to handle HTTP / 1.0 404


I will not repeat here all the reasons for those or other steps and settings, I will briefly list what can be found on the Internet .
')
  1. Create a beautiful 404 page in our Joomla. There are several ways to do this when implementing your particular logic and how to select them for
    a visitor;
  2. In our template, which is used on the site as the main frontend template, from the system system template, we rewrite the error.php file;
  3. Then we edit this file in order to follow the following logic - if we catch the error 404 - then first issue the HTTP / 1.0 404 header, and then output the page that we previously prepared. Suppose the number (ID) of our “beautiful 404 page” is 1001. The error.php file in your template might look like this:

defined('_JEXEC') or die; if (!isset($this->error)) { $this->error = JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); $this->debug = false; } // Get language and direction $doc = JFactory::getDocument(); $app = JFactory::getApplication(); $this->language = $doc->language; $this->direction = $doc->direction; if($this->error->getCode()=='404') { header("HTTP/1.0 404 Not Found"); header('Location: index.php?option=com_content&view=article&id=1001'); } 

Now we check. Enter the site address. Next - abracadabra after the symbol /. Works? Works, which was to be expected.

What's the catch?


Open the debugging of pages in your favorite browser (my favorite browser is Fitefox with Firebug), the “Network” tab, and look at the headers with which the browser communicates with the site.

Enter the site address - HTTP / 1.0 header 200 OK

Now abracadabra ... We are waiting for HTTP / 1.0 400 Not Found - look at the headers:

  1. First HTTP / 1.0 302 Found
  2. Then our beautiful page is given to the browser with the code HTTP / 1.0 200 OK

image

What is bad?


- But, after all, works? - You say. Yes it works. And how does the search engine look at it?

I had the relocation of the site pages from one section (folder) of the site to another. But not all pages should have moved. Pages of the old section of the site were in the index. Those that moved were issued with the HTTP / 1.0 301 Moved Permanently code (classics of the genre) and the search engines correctly “moved” to a new location. And those that were supposed to "sink into oblivion" - and flashed in the index, although they were physically absent from the site, and when they were accessed, a "beautiful page 404" was issued, but not HTTP / 1.0 404 code (see above).

Way out of this situation


For pages with error 404, I decided to issue the HTTP / 1.0 404 Not Found header and do not redirect through the Location header, but read the stream of “beautiful page 404” and redirect it to the browser. Here is the implementation:

 if($this->error->getCode()=='404') { header("HTTP/1.0 404 Not Found"); $url=JURI::root()."index.php?option=com_content&view=article&id=1001"; $data = file_get_contents($url) or die("Cannot open URL"); echo $data; } 

Now, the required page is returned to the visitor in case of error 404, and the search engine actually sees the code 404 and considers the entered address as Not Found.

Source: https://habr.com/ru/post/271225/


All Articles