开发者

Fastest way to match uri string

开发者 https://www.devze.com 2023-04-01 05:21 出处:网络
The following code is in the index.php file of my site and runs every time a page on my website is queried. Both of these requires execute there own respective 404 error pages so dont worry about that

The following code is in the index.php file of my site and runs every time a page on my website is queried. Both of these requires execute there own respective 404 error pages so dont worry about that. What is the most performance efficient way of doing this within php?

$cache = $_SERVER['REQUEST_URI'];

if(preg_match('/^\/blog/',$cache) || preg_match('/^\/portfolio/',$cache)){
  define('WP_USE_THEMES', true);
  // Loads the WordPress Environment and Template
开发者_StackOverflow社区  require('./wordpress/wp-blog-header.php'); 
}else{
  // Load codeigniter
  require('./codeigniter/index.php');
}


$cache = $_SERVER['REQUEST_URI'];

if (0 === strpos($cache, '/blog/') ||
    0 === strpos($cache, '/portfolio/'))
{
    define('WP_USE_THEMES', true);
    require('./wordpress/wp-blog-header.php'); 
}
    else
{
    require('./codeigniter/index.php');
}

No Regex needed and it is super fast.

0

精彩评论

暂无评论...
验证码 换一张
取 消