1. In Laravel 6, the request with query parameters is lost after the 302 jump. as shown in Figure 1

2. The original plan to determine whether the query parameter exists at a specific request. If it exists, it will be automatically brought with it after the 302 jump. However, this scheme cannot be avoided that there may be other requests and similar problems in the follow-up. In the final decision, the problem of missing request query parameters after the 302 jump is uniformly handled based on the post-middleware.
3. Put the newly created middleware into the web middleware group, because it only needs to be applied to the web UI.
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
// ...
\App\Http\Middleware\ThemeEditorQueryParam::class,
]
];
4. Implement redirect to named route in a controller method
return redirect()->route('account_login');
5. Add query parameters based on the League/URI, and execute the composer require League/uri-components and composer require League/URI. Reference: In PHP 7.4, for URI, add query parameters based on League/URI
6. The code in the middleware is implemented as follows
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\RedirectResponse;
use League\Uri\Uri;
use League\Uri\UriModifier;
class ThemeEditorQueryParam
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
// 当响应为重定向时,判断请求中是否存在请求参数:oseid
if ($response instanceof RedirectResponse) {
$oseid = $request->query('oseid'); // 主题编辑器的主题的预览(2.0)
if (isset($oseid)) {
$uri = Uri::createFromString($response->getTargetUrl());
$editorUri = UriModifier::mergeQuery($uri, 'oseid=' . $oseid);
$response->setTargetUrl($editorUri->jsonSerialize());
}
}
return $response;
}
}
7. Open the URL:https://xxx.local/products/ri-yuan-ce-shi-bian-zhong?variant=656, without the OSEID parameter, 302 jumps to:https://xxx.local/account/login. in line with expectations. as shown in Figure 2

8. Open the URL:https://xxx.local/products/ri-yuan-ce-shi-bian-zhong?variant=656&oseid=6462e3db4cd20, with the OSEID parameter, 302 jumps to:https://xxx.local/account/login?oseid=6462e3db4cd20. in line with expectations. as shown in Figure 3

PHP / Laravel / Yii2 Legacy Project Maintenance & Long-Term Technical Support
If your PHP / Laravel / Yii2 project is already in production but needs bug fixing, API troubleshooting, performance optimization, developer handover support, or long-term maintenance, feel free to contact me for remote technical support.
Ideal For:
✅ PHP legacy systems without active maintenance
✅ Laravel / Yii2 project bug fixes
✅ Admin panel feature iterations
✅ RESTful API troubleshooting
✅ MySQL / Redis / Nginx performance issues
✅ Long-term remote part-time maintenance
We can start with a small task:
✅ Production error troubleshooting
✅ API issue analysis
✅ Slow query and performance bottleneck diagnosis
✅ Initial code structure review
✅ Deployment environment and log inspection
If you would like to discuss your project, please contact me and mention: PHP Maintenance Consultation.
Contact Me:
Telegram: @shuijingwan
WeChat: 13980074657
Email: shuijingwanwq@gmail.com

Leave a Reply