作者 邓超

redirect

... ... @@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Fun;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
... ... @@ -18,8 +19,13 @@ class Controller extends BaseController
* @author:dc
* @time 2023/1/16 9:22
*/
public function redirect($url){
$url = urldecode($url);
public function redirect(){
$url = urldecode(request()->get('url'));
if(empty($url)){
Fun::abort();
}
if(!preg_match("/^http(s?):\/\//",$url)){
$url = 'http://'.$url;
}
... ...
... ... @@ -143,7 +143,7 @@ class Index extends Base
$urls)
){
foreach ($urls[1] as $k=>$url){
$_url = str_replace($url,'/redirect-'.urlencode($url),$urls[0][$k]);
$_url = str_replace($url,'/redirect?url='.urlencode($url),$urls[0][$k]);
$data['html'] = str_replace($urls[0][$k],$_url,$data['html']);
}
}
... ...
... ... @@ -66,10 +66,14 @@ Route::get('/blog', [\App\Http\Controllers\V2\Index::class,'blog']);
Route::get('/blog/{id}', [\App\Http\Controllers\V2\Index::class,'blog_info'])->where('id','\d+');
// 单页
Route::get('/page/{key}', [\App\Http\Controllers\V2\Index::class,'page'])->where('key','[a-z_\-\d]{2,}');
// 单页的另一种方式
Route::get('/{key}', [\App\Http\Controllers\V2\Index::class,'page'])->where('key','[a-z_\-\d]{2,}');
// 跳转页面
Route::get('/redirect-{url}', [\App\Http\Controllers\Controller::class,'redirect']);
Route::get('/redirect', [\App\Http\Controllers\Controller::class,'redirect']);
// 单页的另一种方式 这个是通用的匹配
Route::get('/{key}', [\App\Http\Controllers\V2\Index::class,'page'])->where('key','[a-z_\-\d]{2,}');
... ...