[Pro] 404 Pages / ExpressionEngine

I’m trying to figure out how to do 404 pages using EE as well as the server itself. So, if people went to:

www.example.com/!

Then it would redirect to a 404 page. However I’d like EE to handle the 404 page part but it won’t do that or I’m just doing it wrong. I tried doing the conditional segment URL parsing with the suggestion from atelier here:

http://freewaytalk.net/thread/view/61467

But I can’t figure out if I’m supposed to put it on the single entry page or on the index page that links to the single entry page. I tried doing:

{if segment_1 == "template_group_name"}
	{if segment_2 == "template_name"}
		{if segment_3 != ''}
			{redirect="error/404"}
		{/if}
	{/if}
{/if}

on the single entry page (seems like a bit of overkill) and it just loops the single entry strangely. So, I’m assuming that’s a no go. Does it need to be in HTML Markup in the page header? If so, where? (Before HTML, Before Head?, etc) I also tried using the conditional of ‘no_results’ and that doesn’t work either.

Any guidance would be great.

Here’s a few other ideas:

  1. I removed the index.php from the URL using the .htaccess.
  2. Is there a way through the .htaccess file I could load the 404 page BECAUSE…
  3. I’m guessing the 404 page outside of EE will have to be created separately, but anything inside EE will use the 404 page.
  4. I also changed the ‘Global Template Preferences’ to go to the 404 template and I also enabled ’ Strict URL’s’.

Thanks in advance.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Solved one issue of the server side. I added:

ErrorDocument 404 /index.php?/error/404

to my .htaccess file and that part works.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Dan

Unfortunately I do not know nothing about htaccess. But I’ve read here http://expressionengine.com/docs/general/throttling.html that EE handles the 404 if it (she??) sees an invalid URL. You can set the 404 page in the throttle settings. In my example the template-group and the template exist, so that’s a valid URL for EE. Only that segment_3 is missing, therefore for my part the URL is invalid. When you put the conditional in the doc before the HTML, EE loads that first, and makes the redirect. Without loading the page. (There is even a methode to do that with PHP, that’s really slick.) Your conditional is indeed a bit of an overkill.
Hope this was at help.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

forgot, link to the PHP methode.
http://expressionengine.com/docs/templates/globals/url_segments.html Tip is at bottom of page. (I myself have not managed to get that work, due to lack of PHP knowledge)


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks for the help again, atelier.

However and which-ever place I put it, it just won’t go as a page HTML markup. I’ve read and re-read my code and I even looked at it in Textmate and it was as it should be.

I did find that if I toss in a conditional of:

{if no_results}{redirect="404"}{/if}

into any single area that has a weblog entries tag in it that it works fairly well. There’s some totally whacked out ways of getting invalid URL’s, but I doubt things will ever get to that point.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I’m sorry it did not work. You are on build 1.6.8 otherwise a redirect would not work in the first place. And EE handles the 404 correctly on it’s own terms if it knows where the 404 lives. The methode I mentioned is beside the normal EE procedure. The conditional {if segment_3==“”}{redirect=“404”}{/if} must be before the HTML on the single entree page. Then all request that call just mysite/index.php/templategroup/template/ is redirected. Because correct URL is mysite/index.php/templategroup/template/entree (Where entree= third segment) But I’m a bit confused because of what you wrote earlier in this post. Did you remove the index.php in the .htaccess?? Could cause some unexpected things.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I did remove the index.php suffix to the URL by using the ‘Include List’ method (I think that’s what it was called) because I wanted to have clean URL’s. Plus all the other methods, at least with my experience, failed on my hosting provider.

However, with that removed it still doesn’t matter as the segments in the URL start with the template group being ‘segment_1’ and the template name being ‘segment_2’ and would remain that way even if index.php was still in the URL.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

OK, thanks for the info. Did you happen to read this as well?

http://expressionengine.com/docs/modules/weblog/parameters.html#par_req_entry


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options