[英]Redirect to specific controller if url starts with xyz in Laravel
I need to redirect to specific url in Laravel if the url starts with content or video or picture or videos or pictures or etc... 如果网址以内容或视频或图片或视频或图片等开头,我需要重定向到Laravel中的特定网址...
I have written this concept in plain php but how this can be written in Laravel. 我已经用普通的php编写了这个概念,但是如何用Laravel编写。
redirect.php redirect.php
<?php
if(isset($_GET['name']))
{
$link = $_GET['name'];
$request = parse_url($link);
echo $request["path"];
}
?>
.htaccess .htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} /content/ [OR]
RewriteCond %{REQUEST_URI} /videos/ [OR]
RewriteCond %{REQUEST_URI} /video/ [OR]
RewriteCond %{REQUEST_URI} /contents/ [OR]
RewriteCond %{REQUEST_URI} //contents/
RewriteRule .* http://localhost/redirect.php?name=http%1://%{HTTP_HOST}%{REQUEST_URI} [R,QSA,B]
Examples 例子
http://localhost:8048/content/23423/nice-up-civic-poll.html
http://localhost:8048/video/43432/something-here.html
http://localhost:8048/videos/2354323/good-nice.html
http://localhost:8048/contents/451425/breakup-actor.html
http://localhost:8048/content/time/451425/breakup-actor.html
http://localhost:8048/video/watch/1233456/accident-occured.html
You have to configure your routes like this: 您必须像这样配置您的路线:
Route::get("/content/{path}", ...)->where("path", ".*");
Route::get("/video/{path}", ...)->where("path", ".*");
Route::get("/picture/{path}", ...)->where("slug", ".*");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.