-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Docs] Add cookbook for exposing a 404 page
- Loading branch information
Showing
5 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Exposing a not found page | ||
|
||
Since Stenope is a static site generator, it does not handle 404 errors for missing pages. | ||
Instead, your web server should handle them. | ||
|
||
However, you can let Stenope generate a 404.html page for you, and let your web server serve it. | ||
|
||
For instance, add in your `config/routes.yaml`: | ||
|
||
```yaml | ||
errors_404: | ||
path: 404.html | ||
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController | ||
defaults: | ||
template: errors/404.html.twig | ||
options: | ||
stenope: | ||
sitemap: false | ||
``` | ||
and create the `templates/errors/404.html.twig` template: | ||
|
||
```twig | ||
{% extends 'base.html.twig' %} | ||
{% block title %}Page not found{% endblock %} | ||
{% block content %} | ||
<h1>404 Not Found</h1> | ||
<p>The page you are looking for does not exist.</p> | ||
{% endblock %} | ||
``` | ||
|
||
Then, configure your web server to serve this page when a 404 error occurs. | ||
|
||
Nginx: | ||
|
||
```nginx | ||
server { | ||
# […] | ||
location / { | ||
try_files $uri $uri/index.html =404; | ||
} | ||
location ~ \.html { | ||
internal; | ||
} | ||
error_page 404 /404.html; | ||
``` | ||
|
||
Apache: | ||
|
||
```apacheconf | ||
ErrorDocument 404 /404.html | ||
``` |
File renamed without changes.