18

I would create a Single with the URI set to "404", and also set its Template to "404". That entry will automatically get loaded if you go to http://example.com/404, and load your 404.html template, so at the top of the template you should add this to it: {# # Fetch the 404 Single entry, if we don’t already have it. # (requests to /404 will already have ...


8

You're definitely on the right track, just missing out on a couple of key details! The actionUrl function generates a normal, full URL... it's not (by default) an AJAX call. So your browser is actually navigating away from the previous page, and pinging your controller as a completely separate HTTP request. Which leads to the next detail... Unless you're ...


6

Yes, use errorTemplatePrefix. 'errorTemplatePrefix' => "pages/",


4

Anywhere you've currently got something that looks like this: {% if message is defined %}{{ errorList(message.getErrors('fromEmail')) }}{% endif %} Try changing that to: {{ message is defined and message ? errorList(message.getErrors('fromEmail')) }} And you'll want to do that for the other attributes, too ('fromName', etc.).


4

One solution (without needing to create a custom plugin) would be to add a lightswitch or checkbox field called useDefaultLocale, and add it to the field layout of any sections that you want to default to english. In your template you can test for the value of this field and display the default locale version of the content. You would of course need to ...


4

404 isn’t a valid redirect status code, which is why {% redirect '/' 404 %} isn’t working correctly. It sounds like you want to: first issue a 301 or 302 redirect to the homepage then serve the homepage, but with a 404 status If I’m understanding you correctly, even if you could pull it off (maybe doable with a query string or something stored on the ...


4

I pondered this for a while, and then did this, which will direct us to specific entries (not templates, I don't want to create more of those): {# We need a unique 404 for each site - just take us to the right slug relative to current URL #} {% switch currentSite.id %} {# siteA.com #} {% case 1 %} {% redirect '/my-404-slug' %} {# siteB.com #} {% ...


3

Cleared the log files found at /storage/logs/web.log. Tried to view an inner page on the website which threw a Craft "Internal Server Error". Inside the log, I saw "Twig\Error\SyntaxError: Unknown "dump" function". Googled that message and found the solution. For other newcomers, when you set devMode to true, the dump() function is available in your ...


3

So it looks like you're using the old syntax for SEOmatic 1.x for Craft 2.x; here's how you do the same thing in SEOmatic for Craft 3: {% do seomatic.meta.seoTitle("Some Title") %} c.f.: https://github.com/nystudio107/craft-seomatic#twig-templating


3

First, I don’t think your pagination navigation is limiting to just 6 pages like you think it is. The number you pass into paginate.getPrevUrls() and paginate.getNextUrls() will determine how many URLs the functions should return. So if you’re on the 3rd page, calling paginate.getNextUrls(5) will give you the URLs for pages 4-8. Navigation-wise, what you’re ...


3

It turned out that when I deleted news/ from the entry URL format, I also deleted it from the entry template path as well because I misunderstood what that field was for (and forgot to revert that change when everything broke). Thanks to @Brad for drawing my attention to it.


3

It's quite possible that you are in Dev mode. If you switch to false, the 404.html may then be recognized… Look at general.php, then change devMode to false. // Dev environment settings 'dev' => [ 'devMode' => true, ],


3

Looking at your screenshots, the host names are different. The cPanel 404 shows mysphotos instead of myphotos. Probably a typo somewhere in your templates.


3

Since files that begin with a dot are hidden by default in Unix-based systems like OS X, Craft ships with a “htaccess” file rather than “.htaccess”. If you are using Apache and want to use this file, you need to rename it to .htaccess when you upload it to your web server. Not sure why suddenly your site stopped working, but I can tell you that Craft auto-...


3

Check and make sure your .htaccess file is in your public HTML folder public/.htaccess! If you do not include your .htaccess file in your public folder, Craft will display your home page properly, but all other pages will fail to load unless you add index.php?p= in your URL. Without .htaccess: http://website.com/mypagethatreallyexists = 404 Without ....


2

404 redirect: You could set up your single to use 404-not-found (example) as a uri, and add a redirect: {% redirect '/404-not-found' %} to the /404.html file. That way every 404-page gets redirected to the single. Downside: You will loose the 404-header, and the uri in the address-bar will be lost. . Load Single: Set up a single, and load the single ...


2

Probably your paths are not set up right; or the SERVER_NAME isn't what you think it is, so it's not matching the paths in your general.php


2

So my issue was very simple to solve once I paid better attention. The 404 was loading perfectly fine the whole time, my problem was that in my 404 file I had it as {% block content %} and not {% block main %} as I had specified in my layout.


2

Turns out the general.php file had the following line (docs) in it: 'errorTemplatePrefix' => "_errors/" Once I'd created the proper folder and files, all worked as expected. Thanks, @CraftCMS Twitter person!


1

Try adding this to the beginning of your case study entry template: {% if entry is not defined %} {% exit 404 %} {% endif %} Do you have a route set up for your case studies? I've got routing set up on a client site that has the route /case-studies/* pointing to template /_cs/entry.twig That makes it try to the load the template, whether or not ...


1

The error indicates you're trying to use a Twig filter that doesn't exist in your 404 template at line 4. Maybe you've got a plugin that added it's own filter, but you don't have the plugin installed or enabled? Update: Based on the follow up comments, the error message is very misleading and not sure where it is coming from. The 404 template doesn't ...


1

That solution is viable. You can just test to see if the entry or the template matches your 404 template/entry. If you routed everything correctly to display a 404 in case of error, you should be fine.


1

Here's more than you ever wanted to know on 404 and error templates in Craft CMS: Handling Errors Gracefully in Craft CMS


1

Try setting omitScriptNameInUrls to true in your craft/config/general.php file.


1

This is something I discuss in the Handling Errors Gracefully in Craft CMS article, not just for 404s, but for a number of different status codes/errors. The actual templating code then ends up looking something like this for error.twig: {# @var craft \craft\web\twig\variables\CraftVariable #} {% set entry = craft.entries.section("genericError").one() %} {...


Only top voted, non community-wiki answers of a minimum length are eligible