Skip to content

Commit 7e2bb47

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents ed0de7d + ef64224 commit 7e2bb47

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Redirects to and from
88
- Set the status of redirects
9+
- Supports headers on redirects
910
- Regex Redirects
1011
- Imports and Exports
1112

@@ -19,33 +20,42 @@ composer require alt-design/alt-redirect
1920

2021
## Basic usage
2122

22-
### Simple redirects
23+
### Simple redirects
2324
Just take a request to one URL and redirect to a new url, for example
2425

25-
From :
26+
From :
2627
```
2728
/old-page
2829
```
29-
To :
30+
To :
3031
```
3132
/new-page
3233
```
3334

34-
### Regex redirects
35+
### Regex redirects
3536
These, other hand, allow much richer redirect functionality.
3637
Lets say you changed a wildcard URL path to be a query parameter on a new page, this can done like so
3738

38-
From :
39+
From :
3940
```
4041
/old-page/(.*)
4142
```
42-
To :
43+
To :
4344
```
4445
/new-page?wildcard=$1
4546
```
4647

4748
the '$x' (where x is a number) elements are arranged in the order the corresponding '(.*)' appeared in the 'From' URL, this allows rearranging the regexed fields in the 'To' URL.
4849

50+
### Headers on redirect
51+
You can add headers to the redirect response using the addon's config file. To get started, publish the config file to your site:
52+
53+
```bash
54+
php artisan vendor:publish --tag=alt-redirect-config
55+
```
56+
57+
In the `headers` property, you can provide an array of headers to be passed to the `redirect` method.
58+
4959
## Questions etc
5060

5161
Drop us a big shout-out if you have any questions, comments, or concerns. We're always looking to improve our addons, so if you have any feature requests, we'd love to hear them.

config/alt-redirect.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Headers
8+
|--------------------------------------------------------------------------
9+
|
10+
| A key/value pair array of Headers to be included with the redirect. This
11+
| applies to all redirects. For example:
12+
|
13+
| 'headers' => [
14+
| 'Cache-Control' => 'no-cache, must-revalidate',
15+
| ];
16+
|
17+
*/
18+
19+
'headers' => []
20+
21+
];

src/Http/Middleware/CheckForRedirects.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function handle(Request $request, Closure $next, string ...$guards): Resp
4343
return $next($request);
4444
}
4545
if (!($redirect['sites'] ?? false) || (in_array(Site::current(), $redirect['sites']))) {
46-
return redirect($to , $redirect['redirect_type'] ?? 301);
46+
return redirect($to , $redirect['redirect_type'] ?? 301, config('alt-redirect.headers', []));
4747
}
4848
}
4949
}
@@ -54,7 +54,7 @@ public function handle(Request $request, Closure $next, string ...$guards): Resp
5454
if (preg_match('#' . $redirect['from'] . '#', $uri)) {
5555
$redirectTo = preg_replace('#' . $redirect['from'] . '#', $redirect['to'], $uri);
5656
if (!($redirect['sites'] ?? false) || (in_array(Site::current(), $redirect['sites']))) {
57-
return redirect($redirectTo ?? '/', $redirect['redirect_type'] ?? 301);
57+
return redirect($redirectTo ?? '/', $redirect['redirect_type'] ?? 301, config('alt-redirect.headers', []));
5858
}
5959
}
6060
}

0 commit comments

Comments
 (0)