0

I have a slim framework application in the root directory /.

I have a wordpress install in the '/blog/' child directory.

This is all fine and well as i can easily access the /blog/ folder and any physical files.

However, the problem occurs when using the permalinks in wordpress. I haven't found a way to pass the request over to wordpress correctly.

So the first thing i tried was this:

$app->slim->notFound(function() use($app) { 
    //to make pretty url's work with turdpress, we must see if that request was intended for our blog route.
    if(strpos($app->slim->request->getPath(),'/blog/') !== false){
        $app->slim->response()->status(404);
    }else{
        $app->args['title'] .='404 Not Found';
        $app->args['scripts'] = 'js/404.js';
        echo $app->loadTemplate('404.twig')->render($app->args); 
    }
}); 

Here we catch requests for the blog route and return a 404 to nginx. this is what i tried to do with nginx.conf it makes sense to me but doesn't seem to work.

location / {
    include /etc/nginx/mime.types;
    index index.php;
    try_files $request_uri $request_uri/ /index.php?$query_string;
    error_page 404 = @default;
}
location /blog {
    include /etc/nginx/mime.types;
    index index.php;
    try_files $request_uri $request_uri/ /index.php?$query_string;
}

location @default{
    include /etc/nginx/mime.types;
    index index.php;
    try_files $request_uri $request_uri/ /blog/index.php?$query_string;
}

So that is what i tried, and it obviously didn't work. So i had a second idea. Maybe in the NotFound controller, i could just try to include index.php from wordpress, since this is logically the only place that permalinks would be used(or so i would assume). This is gonna be quite a bit of work, so before i go through with it i wanted to see if there were any better ideas hinging around this, or if maybe anyone else has had this problem before with wordpress

1 Answer 1

0

Well, it looks like my latest idea proved correct. Simply including the index file for wordpress was enough to get permalinks working for blog posts.

$app->slim->notFound(function() use($app) { 
    //to make pretty url's work with turdpress, we must see if that request was intended for our blog route.
    if(strpos($app->slim->request->getPath(),'/blog/') !== false){
        include __DIR__ . '/../../blog/index.php';
    }else{
        $app->args['title'] .='404 Not Found';
        $app->args['scripts'] = 'js/404.js';
        echo $app->loadTemplate('404.twig')->render($app->args); 
    }
}); 

I am curious to know if anyone thinks this is dangerous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.