mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
Adding support for aliases (redirects)
This commit is contained in:
33
docs/content/doc/aliases.md
Normal file
33
docs/content/doc/aliases.md
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: "Aliases"
|
||||
Pubdate: "2013-07-09"
|
||||
Aliases:
|
||||
- /doc/redirects/
|
||||
- /doc/alias/
|
||||
---
|
||||
|
||||
For people migrating existing published content to Hugo theres a good chance
|
||||
you need a mechanism to handle redirecting old urls.
|
||||
|
||||
Luckily, this can be handled easily with aliases in Hugo.
|
||||
|
||||
## Example
|
||||
**content/posts/my-awesome-blog-post.md**
|
||||
|
||||
---
|
||||
aliases:
|
||||
- /posts/my-original-url/
|
||||
- /2010/even-earlier-url.html
|
||||
---
|
||||
|
||||
Now when you go to any of the aliases locations they
|
||||
will redirect to the page.
|
||||
|
||||
## Important Behaviors
|
||||
|
||||
1. *Hugo makes no assumptions about aliases. They also don't change based
|
||||
on your UglyUrls setting. You Need to provide a relative path and the
|
||||
complete filename or directory.*
|
||||
|
||||
2. *Aliases are rendered prior to any content and will be overwritten by
|
||||
any content with the same location.*
|
@@ -1,37 +0,0 @@
|
||||
---
|
||||
title: "Redirects"
|
||||
Pubdate: "2013-07-09"
|
||||
---
|
||||
|
||||
For people migrating existing published content to Hugo theres a good chance
|
||||
you need a mechanism to handle redirecting old urls.
|
||||
|
||||
Luckily, this can be handled easily in a couple of easy steps.
|
||||
|
||||
1. Create a special post for the redirect and mark the file as a `redirect`
|
||||
file in the front matter. Here is an example
|
||||
`content/redirects/my-awesome-blog-post.md` :
|
||||
|
||||
```markdown
|
||||
---
|
||||
redirect: true
|
||||
slug: /my-awesome-blog-post/
|
||||
url: /docs/redirects/
|
||||
---
|
||||
```
|
||||
|
||||
2. Set the redirect template `layouts/redirects/single.html`:
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="canonical" href="{{ .Url }}"/>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="refresh" content="0;url={{ .Url }}" />
|
||||
</head>
|
||||
</html>
|
||||
```
|
||||
|
||||
Now when you go to `/my-awesome-blog-post/` it will do a meta redirect to
|
||||
`/docs/redirects/`.
|
@@ -1,5 +0,0 @@
|
||||
---
|
||||
redirect: true
|
||||
slug: /my-awesome-blog-post/
|
||||
url: /docs/redirects1/
|
||||
---
|
Reference in New Issue
Block a user