mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-08 18:51:12 +02:00
* First cut * Temporarily disable composer.json for netlify build * POC * New recursive directory query, various refinements * Fix flexbox * new styled components plugin * Apply frontmatter delimiters * Mobile styles, animation * Search * Redesign, clean up * Nuke the cache, try again * fix file casing * Remove production env file * ID headers * Move app to new repo * Add frontmatter universally * Hide children changelogs * Add how to title * New callout tags * Revert inline code block change * Replace note callouts * Fix icons * Repalce images * Fix icon * Fix image links * Use proper SQL icon
55 lines
1.3 KiB
Markdown
55 lines
1.3 KiB
Markdown
---
|
|
title: Redirection
|
|
summary: Move users around your site using automatic redirection.
|
|
icon: reply
|
|
---
|
|
|
|
# Redirection
|
|
|
|
Controllers can facilitate redirecting users from one place to another using `HTTP` redirection using the `Location`
|
|
HTTP header.
|
|
|
|
**app/code/Page.php**
|
|
|
|
|
|
```php
|
|
$this->redirect('goherenow');
|
|
// redirect to Page::goherenow(), i.e on the contact-us page this will redirect to /contact-us/goherenow/
|
|
|
|
$this->redirect('goherenow/');
|
|
// redirect to the URL on yoursite.com/goherenow/. (note the trailing slash)
|
|
|
|
$this->redirect('http://google.com');
|
|
// redirect to http://google.com
|
|
|
|
$this->redirectBack();
|
|
// go back to the previous page.
|
|
```
|
|
|
|
## Status Codes
|
|
|
|
The `redirect()` method takes an optional HTTP status code, either `301` for permanent redirects, or `302` for
|
|
temporary redirects (default).
|
|
|
|
```php
|
|
$this->redirect('/', 302);
|
|
// go back to the homepage, don't cache that this page has moved
|
|
```
|
|
|
|
## Redirection in URL Handling
|
|
|
|
Controllers can specify redirections in the `$url_handlers` property rather than defining a method by using the '~'
|
|
operator.
|
|
|
|
```php
|
|
private static $url_handlers = [
|
|
'players/john' => '~>coach'
|
|
];
|
|
```
|
|
|
|
For more information on `$url_handlers` see the [Routing](routing) documenation.
|
|
|
|
## API Documentation
|
|
|
|
* [Controller](api:SilverStripe\Control\Controller)
|