Forum

Thread tagged as: Problem, Blog

Rewrite problem with blog tag and category

Hi there, I'm trudging through the process of rewriting URLs and I can't seem to smooth everything out.

I'm on Perch (not Perch Runway).

I've added a folder called "blog" to my site root and in there I've placed "archive.php" and "post.php"

My .htaccess rewrites were taken straight from the video tutorial. And the link updates were made per video instructions. Posts are working fine, but categories and tags are not. Style-wise, it's as if the page is not referencing archive.php, although the post filtering is accurate (see debug below from tag='art'...page path looks fine to me...)

Via trial & error I got the proper archive layout to display by creating a subfolder called "tag" in the blog folder. I placed archive.php in the tag folder and that solved the problem for tag archiving. The rewrite looked like this:

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

I tried to use this new file location to rewrite the category URLs but it did not work. I then followed the same process for categories: created a new "category" subfolder in blog and dropped in a copy of archive.php. It actually worked, however the main category title heading stopped showing up.

I suspect that I shouldn't have to use such a method, so here I am!

I reverted everthing to what I assume should be the proper set up; here it is:

RewriteEngine on

RewriteRule ^blog/category/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?cat=$1&page=$2 [L]
RewriteRule ^blog/category/([a-zA-Z0-9-/]+)$ /blog/archive.php?cat=$1 [L]

RewriteRule ^blog/date/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?year=$1&page=$2 [L]
RewriteRule ^blog/date/([a-zA-Z0-9-/]+)$ /blog/archive.php?year=$1 [L]

RewriteRule ^blog/tag/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?tag=$1&page=$2 [L]
RewriteRule ^blog/tag/([a-zA-Z0-9-/]+)$ /blog/archive.php?tag=$1 [L]

RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$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]

From tag_link.html:

<a href="/blog/tag/<perch:blog id="tagSlug" />" rel="tag"><perch:blog id="tagTitle" /> </a>

debug from tag link, problem is it looks unstyled (the stylesheets links are good):

Time    Δ   Debug Message
0.051   0   SELECT * FROM perch2_pages WHERE pagePath='/blog/archive.php' LIMIT 1
0.0834  0.0325  SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
0.0884  0.005   SELECT * FROM perch2_blog_tags WHERE tagSlug='art' LIMIT 1
0.0906  0.0021  Using template: /templates/mailchimp/subscribe.offcanvas.html
0.101   0.0104  SELECT * FROM perch2_blog_tags WHERE tagSlug='art' LIMIT 1
0.1043  0.0033  SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='postDateTime' WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID ) as tbl LEFT JOIN perch2_blog_posts_to_tags p2t ON tbl.postID=p2t.postID LEFT JOIN perch2_blog_tags t ON p2t.tagID=t.tagID WHERE ( tagSlug IN ('art') AND postStatus='Published' AND postDateTime<='2015-11-16 17:06:00' ) GROUP BY itemID ORDER BY sortval DESC LIMIT 0, 4
0.1174  0.0131  SELECT FOUND_ROWS() AS `count`
0.1178  0.0004  Using template: /templates/blog/archive.html
0.1187  0.0009  SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC
0.1194  0.0007  SELECT * FROM perch2_categories ORDER BY catTreePosition ASC
0.13    0.0106  SELECT t.tagTitle, t.tagSlug, COUNT(p2t.postID) AS qty FROM perch2_blog_tags t, perch2_blog_posts_to_tags p2t, perch2_blog_posts p WHERE p2t.tagID=t.tagID AND p2t.postID=p.postID AND p.postStatus='Published' AND p.postDateTime<='2015-11-16 17:06:00' GROUP BY t.tagID ORDER BY t.tagTitle ASC
0.1312  0.0012  Using template: /templates/blog/tag_link.html

Thanks so much for reading through this!

Olympia Kyriakides

Olympia Kyriakides 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

We have a really nice routing engine in Runway that makes these headaches go away!

Good advertising! I'm sold :) Thanks Drew! i <3 perch