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 7, 2022
1 parent 12fb355 commit d428bd9
Show file tree
Hide file tree
Showing 2 changed files with 30 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
28 changes: 28 additions & 0 deletions docs/api/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,34 @@ Hello wörld!
> });
> ```
## HTTP Redirects
There are two ways in X to redirect incoming HTTP requests to a new location. You
can either use the [redirect helper method](https://framework-x.org/docs/api/app/#redirects)
for simpler use cases or go the manual way and define your own HTTP response:
```php
<?php
// …
$app->get('/users/user', function () {
return new React\Http\Message\Response(
React\Http\Message\Response::STATUS_MOVED_PERMANENTLY,
[
'Location' => '../user'
]
);
});
```
Redirect responses have status codes that start with 3, and a Location 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.

## HTTP caching

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

0 comments on commit d428bd9

Please sign in to comment.