Forum
Mod Rewrite - Blog posts direct to error 404
I can't seem to rewrite my urls successfully, i have used:
RewriteRule ^/([a-zA-Z0-9-/]+)$ /post.php?s=$1 [L]
and in the perch login
{postSlug}
What am i forgetting? My diagnostic report is below:
Perch: 2.8.11, PHP: 5.6.11, MySQL: 5.0.91, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (2.8.11), assets (2.8.11), categories (2.8.11), perch_blog (4.6)
App runtimes: <?php include(PERCH_PATH.'/core/apps/content/runtime.php'); include(PERCH_PATH.'/core/apps/categories/runtime.php'); include(PERCH_PATH.'/addons/apps/perch_blog/runtime.php'); ?>
PERCH_LOGINPATH: /perch
PERCH_PATH: /home/zurimaga/public_html/perch
PERCH_CORE: /home/zurimaga/public_html/perch/core
PERCH_RESFILEPATH: /home/zurimaga/public_html/perch/resources
Image manipulation: GD
PHP limits: Max upload 128M, Max POST 128M, Memory: 256M, Total max file upload: 128M
Resource folder writeable: Yes
HTTP_HOST: zurimagazine.com
DOCUMENT_ROOT: /home/zurimaga/public_html
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Is your post.php in the root of your site? That rewrite rule assumes it is.
Hi Rachel,
Yes it is, all my blog files are in the root.
That will cause you problems as you'll be matching any files, I'd suggest putting them in a folder /blog.
See the video here: https://docs.grabaperch.com/video/v/simple-url-rewriting/
Hmm, I can do that but that'll mean i have to redirect my customers to /blog/ whenever they land on the root as there's no other files there. Is there something I can add to the .htaccess file to do this?
You listing could be in the root but I would suggest you put the detail page into a folder. It'll make it easier for you to rewrite the URLs.
Ahh, so only put post.php in /blog/ but the rest of the perch files on the root?
yes you could do that.
Wonderful, thank you for your help Rachel. I'll have a go at this im about 20mins and let you know how it pans out. If all goes well, I'll mark it as a solution to end the thread :)
Hi Rachel, the blog post rewriting has worked perfectly, however I've added your additional ones below:
and it hasn't worked, any ideas why? I have archive.php within /blog/
What isn't working, and how is it failing?
Hi Drew,
The url for my categories isn't rewriting, the url string is https://zurimagazine.com/blog/archive.php?cat=natural-hair and i'd like it to be: https://zurimagazine.com/blog/natural-hair
How will your rules distinguish between a post called
natural-hair
and category callednatural-hair
?That is a very good point.. Okay so what if i made a folder within /blog/ called "category" and placed my archive.php in there. Would that work? And what would I add to my .htaccess to rewrite that url?
You don't need the folder - just add that
category
segment to the rewrite rule.Hi Drew,
I'm not too familiar with mod_rewrites and wouldn't know how to do that :( is there a way you can advise me further? Also I have just double checked my url string and it's appearing as..
https://www.zurimagazine.com/blog/03/08/15/archive.php?cat=natural-hair
We can only really support Perch here. There are lots of places to learn how to use mod_rewrite.
I wrote quite a bit about it here: https://24ways.org/2013/url-rewriting-for-the-fearful/