Skip to content

Commit

Permalink
Add instructions for HTTP redirecting
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Apr 21, 2022
1 parent ac24fa4 commit 3dad793
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ crawlers to update their index like this:
$app->redirect('/blog.html', '/blog', React\Http\Message\Response::STATUS_MOVED_PERMANENTLY);
```

See [response status codes](response.md#status-codes) for more details.
See [response status codes](response.md#status-codes) and [HTTP redirects](response.md#http-redirects)
for more details.

## Controllers

Expand Down
30 changes: 30 additions & 0 deletions docs/api/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,36 @@ Hello wörld!
> });
> ```
## HTTP Redirects
To redirect incoming HTTP requests to a new location you can define your HTTP
response like this:
```php
<?php
// …
$app->get('/blog.html', function () {
return new React\Http\Message\Response(
React\Http\Message\Response::STATUS_FOUND,
[
'Location' => '/blog'
]
);
});
```
Redirect responses have a status code in the 3xx range, and a [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
response header holding the URL to redirect to. When a Browser or a search engine
crawler receives a redirect, they will automatically follow the new URL provided
in the `Location` header.

See [response status codes](#status-codes) for more details.

You can also use the [redirect helper method](https://framework-x.org/docs/api/app/#redirects)
for simpler use cases.

## HTTP caching

HTTP caching can be used to significantly improve the performance of web
Expand Down

0 comments on commit 3dad793

Please sign in to comment.