I have a running blog based on WP. Currently, I'm developing a new web app with Laravel which should run on the same (sub)domain. The new web app should be the new start page / homepage / document root www.xyz.xyz/ of the website but I don't want to change the current WP URL structure - I don't want to run WP in a subdirectory - so everything should stay as it is for WP and it's existing URLs beside that the start page should be served by laravel and not wordpress.
Of course, it could happen that a wordpress post and a laravel webpage were using the same slug although it shouldn't, in that case the Laravel page should be served.
I'm using nginx as web server. Has anyone done something like this before? Can it be accomplished on nginx level? Does anyone have a suggestion about how to solve this problem?
The recognition if Laravel can serve the page I'll do in the exception handler, if WP also doesn't have a page to serve it will be responsible to show the 404 - Curling the WP blog works, as long as they are not running on the same subdomain / webserver.
The main question is, how do the index.php and nginx need be configured to serve both, Laravel & WP on the same (sub)domain and running in the same directory.
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $exception * @return \Illuminate\Http\Response */ public function render($request, Exception $exception) {
if ($this->isHttpException($exception)) {
$statusCode = $exception->getStatusCode();
switch ($statusCode) {
case '404':
if(Cache::store('file')->has('magazin-startpage')) {
echo Cache::store('file')->get('magazin-startpage');
return;
}
$queryParameter = str_replace($request->url(), "",
$request->fullUrl());
$path = $request->getPathInfo();
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_PORT , 443);
curl_setopt($ch, CURLOPT_URL,"https://www.blog.xyz"
.$path.$queryParameter);
curl_setopt($ch, CURLOPT_POST, 1);
$blog = curl_exec ($ch);
curl_close ($ch);
Cache::store('file')->put('www.blog.xyz', $blog, 60);
echo $blog;
return;
break;
}
}
return parent::render($request, $exception);
}
Thanks.