Trying to duplicate Portfolio with Categories/Two page list and detail with URL...
Hello,
As the title states, I'm still learning Perch so I'm trying to duplicate the pages from the Portfolio with Categories/Two Page List and Detail tutorials but I'm stuck on the URL rewrite part.
Currently, the Two Page List and Detail pages work perfectly if I link to /detail.php?s=item-slug-here
from the List page. However, if I try to link to /detail/item-slug-here
the custom content block on the Detail page will no longer load.
My code is near exact recreations of the tutorial material...
portfolio.php contains....
<?php
perch_content_create('Portfolio', array(
'template' => 'portfolio_item.html',
'multiple' => true,
'edit-mode' => 'listdetail',
));
perch_content_custom('Portfolio', array(
'template' => 'portfolio_listing.html',
));
?>
detail.php
<?php
perch_content_custom('Portfolio', array(
'page' => '/portfolio.php',
'template' => 'portfolio_item.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1,
));
?>
portfolio_listing.html and portfolio.item.html are also replicas of the tutorial material and thus far function as expected within the admin area and when viewed on a non-pretty URL.
.htaccess looks like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^detail/([a-zA-Z0-9-]+)$ /detail.php?s=$1 [L]
RewriteRule ^category/([a-zA-Z0-9-/]+)$ /category.php?cat=$1 [L]
# Redirect to PHP if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
</IfModule>
I've also tested that the mod_rewrite module is working and my .htaccess file is accessible (the last rule is currently working and I can easily do simple URL rewrites and redirects) so unless I'm missing something that should not be the problem.
Finally, if it helps, I'm working locally on MacOS apache and my diagnostics report is as follows:
Perch: 2.8.6, PHP: 5.4.30, MySQL: mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $, with PDO Server OS: Darwin, apache2handler Installed apps: content (2.8.6), assets (2.8.6), categories (2.8.6) App runtimes: <?php $apps_list = array( 'content', 'categories', ); PERCH_LOGINPATH: /perch PERCH_PATH: /Users/jennifer/Sites/jennifercodes/perch PERCH_CORE: /Users/jennifer/Sites/jennifercodes/perch/core PERCH_RESFILEPATH: /Users/jennifer/Sites/jennifercodes/perch/resources Image manipulation: GD PHP limits: Max upload 500M, Max POST 500M, Memory: 128M, Total max file upload: 128M Resource folder writeable: Yes HTTP_HOST: jennifercodes.dev DOCUMENT_ROOT: /Users/jennifer/Sites/jennifercodes/ REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Please help me because I'm really at a loss for why this won't work.
I've continued on with the Portfolio with Categories video-tutorial and I'm having the same difficulty with the categories URL rewrite...
/category.php?cat=skills/sketch-adobecs/
works fine, but/category/skills/sketch-adobecs/
does not pull up the corresponding portfolio items.I don't understand WHY but it appears as if the slug ID and the cat ID are not being passed.
Do you have any rewrite rules working?
These are working...
and if I do something silly like
it totally works.
What is interesting, is that if I remove ALL content from my .htaccess file, I can still access example.php by directing my browser to /example.... portfolio.php from /portfolio
Additionally, if I visit /detail/test-item-1 detail.php does pull up in the browser sans the portfolio_item content (just as it would with the rewrite rules in place in .htaccess).
Any idea what is going on here? I'm stumped.
RewriteRule shazaaam.html example.php
does NOT still work if I remove it from .htaccess - so I'm taking that as evidence that apache is at least using my .htaccess file.Are your
detail.php
andcategory.php
files in the root of the site?They are.
If it helps... this is how I have my server set up.
Apache root is pointing to:
/Users/myusername/Sites/
within that folder are two different Perch sites that I'm tinkering with... so I have
/Users/myusername/Sites/site-1
/Users/myusername/Sites/site-2
In site-2 I'm trying to build something similar to the list/detail + Portfolio w/categories tutorials so I've been following them as a learning experience.
So, I've got my .htaccess file located in
/Users/myusername/Sites/site-2/
along withdetail.php
portfolio.php
category.php
etc.Is the problem that I have two perch installs within /Sites?
Ok, so they're not in the root of the site - they're in a subfolder, right?
/detail.php
is actually/site-2/detail.php
?I guess that would be correct, yes.
So I changed my rewrite rules to:
And it still doesn't work.
Forgot to mention - I also have virtual hosts set up for each perch site...
httpd-vhosts.conf contains:
I'm probably making some n00b mistake somewhere in all this but I can't suss out what it is.
Shouldn't that be:
That does not work either.... I've run this problem by a couple of the devs I work with and they're stumped too.
The best guess we can come up with at this point is that perhaps the slug is not getting passed to the
perch_content_custom
filter located indetail.php
. When I point my browser at the 'prettified' url, detail.php does load, the problem is that the content that would be pulled in by theperch_content_custom
tag is just not there.Thoughts?
I even when into
httpd.conf
andhttpd-vhosts.conf
and reset my server root to /Users/myusername/Sites/site-2 ... still doesn't work.Are you saying that the rewrite is working? I thought the issue was that the rewrite wasn't working.
Well... it appears that the rewrite is working, but the content is not loading as in the tutorial.
I'm really sorry I was not more clear... I am new to apache rewrites so it has been difficult for me to determine where this is breaking.
Can you add debug to your page and let me know what it outputs?
https://docs.grabaperch.com/docs/installing-perch/configuration/debug/
From /detail/test-item
Clearly no slug coming through there. Can you show me the code on your page where you're filtering with the slug?
perch_content_custom is directly from the tutorial... here's the entire detail.php page:
portfolio_listing.html looks like:
Can you add this to the page and let me know what it outputs?