Forum

Thread tagged as: Question

Finding /blog/post.php when all of perch is in a subfolder

I’m using Perch for just one portion of my site that lives in a folder, so things aren't at the root of the site. I'm having a problem because when I add the <perch:blog id="postURL" /> to link to individual posts I'm getting a 404 because it can't find the /blog/post.php which is because it's actually at /[FOLDER]/blog/post.php

I've done a lot of searching around but can't figure out what I need to change to tell Perch to look in the right place for the post.php file. Anyone know what I should be changing? Or maybe I'm diagnosing this problem incorrectly?

Susan Robertson

Susan Robertson 0 points

  • 2 months ago

I've not installed Perch in a sub-folder but what do you have for "Blog post page path" in Admin - Settings?

I do have the folder it's in there, so it's /[FOLDER]/blog/{postSlug} and in the url for the link to an individual post it's correct when I look at it rendered in the page, which is why I'm stumped on it not finding the /blog/post.php file.

Drew McLellan

Drew McLellan 2617 points
Perch Support

What value is postURL outputting?

So the url that I'm getting is /microblog/blog/2018-09-06-post-37 for the latest post when I have <perch:blog id="postURL" /> in the href. I'm doing the URL rewriting for a clean url that's talked about here: https://docs.grabaperch.com/addons/blog/examples/clean-urls-perch/. My rewrite is as follows:

<IfModule mod_rewrite.c>  
    RewriteEngine on  
    RewriteRule ^microblog/blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]
</IfModule>

Perch is sitting in a folder of microblog on my site (at https://susanjeanrobertson.com/microblog/), I'm using it just for that and then the rest of my site uses Jekyll. I realize this is a bit of odd usage, but I didn't want to change over my whole site when I really only wanted the ability to update my microblog from the web easily.

Drew McLellan

Drew McLellan 2617 points
Perch Support

So the url that I'm getting is /microblog/blog/2018-09-06-post-37

Is that not correct? It looks correct.

It is the correct url, but when I go to the url I get the 404 that it can't find /blog/post.php which is why I'm confused.......

the file is there at /microblog/blog/post.php should I think it should find it, but it's not :(

Drew McLellan

Drew McLellan 2617 points
Perch Support

Ok, how can I help?

So I did an experiment to see what happens and if I move the file for the post.php to a folder blog at the root, it works (with errors due to not finding runtime.php etc because I just wanted to see what happens and wasn't trying to make everything work.

Is there a reason that Perch is looking for that file at the root when I have the entirety of Perch in a folder? In my blog admin settings I have my url as being the one with the /microblog on the end and I've set everything else up for that, but Perch is looking for that file in a place that I don't think it should be looking. And I'm not sure why.

Drew McLellan

Drew McLellan 2617 points
Perch Support

Are you having problems with routing or with outputting links?

Routing I think. For some reason Perch is looking for the post.php file in the wrong place and I have no idea why.

Drew McLellan

Drew McLellan 2617 points
Perch Support

Do you still have this rewrite rule in place?

RewriteRule ^microblog/blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]

Yes I do, on my production site I'm not linking to the individual posts yet, so I've left all the other stuff there for when I figure out what the problem is.

Drew McLellan

Drew McLellan 2617 points
Perch Support

Is that rule not matching the pages you're having problems with?

So I changed the rule to this:

<IfModule mod_rewrite.c>  
    RewriteEngine on  
    RewriteRule ^microblog/blog/([a-zA-Z0-9-/]+)$ /microblog/blog/post.php?s=$1 [L]
</IfModule>

and it seems I'm getting closer, I now have my site 404 page instead of the browser just telling me it can't find /blog/post.php

The url for the posts is correct now and the rewrite (I think) is correct, but it just doesn't want to use the individual post page to do this.

And I'll be honest, maybe it's time to give up here, because I'm clearly now figuring out what the problem is or how to solve it and I don't know if I can.