1

I've recently launched a new site for a client. Their old site contained a lot of product pages with url parameters such as id=0123.

To try and alleviate people following dead links from Google etc I have implemented a system that looks up the id parameter against their old database, fetches the name of the product and then looks it up in the exp_channel_data table. If a match is found I have a 301 redirect at the top of the 404 template to send the visitor to what is hopefully the correct page.

If no match is found then the 404 page displays (though I may add some other sort of guessed lookup based on some other criteria later).

My question is, will that 301 get sent back to Google BEFORE the 404 response code generated by hitting the 404 template. Will the above method have the desired effect of telling Google that pages have moved to different URLs?

1

The EE 404 page doesn't actually send a 404 header unless you are using a plugin or php in the template to specify that you want if be sent with a 404 header.

6
  • Ah that makes sense actually. Maybe I should ge it to fire back a 404 if the page isn't found. In a moment of clarity I just tested it in a tool that shows me the header response and it works perfectly (other than not sending that 404) – foamcow Apr 8 '13 at 8:46
  • 3
    Actually, this is not true Justin. If you have $config['send_headers'] enabled (which is the default), EE indeed sends a 404 HTTP header in when it generates a 404 page for you (can't find template/template group, or page), and when it loads your 404 template via your own addition of {redirect="404"} inside a template. – Derek Hogue Apr 8 '13 at 12:20
  • 2
    The likely reason this is working for you Pete is that the 301 header you're setting in your template is overwriting the 404 header previously set by EE (this is the default behaviour of the PHP header() function). – Derek Hogue Apr 8 '13 at 12:23
  • Has this always been the case for EE2? I know at least until EE2.4 that you needed I needed to use PHP or a plugin to get valid http headers for 404 pages – Justin Long Apr 8 '13 at 18:59
  • I should probably alter this set up then as I do want 404s sent back. I think the solution is for me to catch requests for details.php?id=XXX (the old url), do my lookups, then redirect to the 404 page if we don't find anything. I'll give it a go and see what response is sent back. Or would that send the 404 back to my details.php script? – foamcow Apr 9 '13 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.