繁体   English   中英

PHP preg_match 正则表达式重定向 url

[英]PHP preg_match regex redirect url

我正在开发一个 Laravel 应用程序,我有以下链接:

http://mywebsite.com/content/*
http://mywebsite.com/products/*
http://mywebsite.com/search/node*
http://mywebsite.com/user/*
http://mywebsite.com/escal/list/*
http://mywebsite.com/node/*
http://mywebsite.com/download/file/fid/*

我需要将这些链接模式重定向到主页: http://mywebsite.com/

我有一个中间件,我试图将所有链接放在一个数组中,我循环遍历数组,同时采用.com/之后的路径并使用substr来测试它是否开始使用request()->path() 但我认为应该使用正则表达式preg_match来完成,但我不知道如何做到这一点。

提前致谢。

$paths = [
'content',
'products',
'search\/node',
'user',
'escal\/list',
'node',
'download\/file\/fid',
];

$patternWithPaths = sprintf('/^http:\/\/mywebsite\.com\/(%s)\//', implode('|', $paths));

if(preg_match($patternWithPaths))
{
  // A match was found, do redirect.
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM