簡體   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