Forum

Thread tagged as: Question, Problem, Blog

URL Rewriting

Hi,

I'm just trying to clean up the URL's on the blog section of a site, having always used Wordpress in the past I'm not used to having to do .htaccess rewrites to clean them up and I'm having some trouble getting them to work.

I've successfully got the posts and the post preview working, so used that as a base to try and sort out sections, archives (month and year), authors and tags. My .htaccess looks like this:

<IfModule mod_rewrite.c>  
    RewriteEngine on  

    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]
    RewriteRule ^blog/tag/([a-zA-Z0-9-/]+)$ /blog/archive.php?tag=$1 [L]
    RewriteRule ^blog/section/([a-zA-Z0-9-/]+)$ /blog/section.php?s=$1 [L]
    RewriteRule ^blog/archive/([a-zA-Z0-9-/]+)$ /blog/archive.php?year=$1 [L]
    RewriteRule ^blog/author/([a-zA-Z0-9-/]+)$ /blog/archive.php?author=$1 [L]

</IfModule>

The debug on a section page is this:

Debug Message
SELECT * FROM perch2_pages WHERE pagePath='/blog/section.php' LIMIT 1
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/blog/section.php' LIMIT 1
Using template: /templates/navigation/item.html
Fetching from cache: perch_blog_sectiona74d480eff88a50c212194b2ddc34d05
SELECT * FROM perch2_blog_sections WHERE sectionSlug='big-house' LIMIT 1
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='_id' WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID ) as tbl WHERE ( sectionID='4' AND postStatus='Published' AND postDateTime<='2015-06-16 17:30:00' ) GROUP BY itemID ORDER BY sortval ASC LIMIT 0, 10
SELECT FOUND_ROWS() AS `count`
Using template: /templates/blog/post_in_list.html
SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC
Fetching from cache: perch_blog_tagsd1e331b756606ce55e1d3d497f301479
Cache file not found: perch_blog_tagsd1e331b756606ce55e1d3d497f301479
SELECT * FROM perch2_blog_sections WHERE sectionSlug='big-house' LIMIT 1
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-06-16 17:30:00' AND p.sectionID=4 GROUP BY t.tagID ORDER BY t.tagTitle ASC
Using template: /templates/blog/tag_link.html
Fetching from cache: perch_blog_date_archive_yearsd724844c2fb9855d33fc20a670fcb457

I'd appreciate any help please.

Phil Bowell

Phil Bowell 0 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

I'm assuming this is Perch and not Perch Runway? In Runway you configure rules via the routing.

If Perch then this video and transcript has examples: https://docs.grabaperch.com/video/v/simple-url-rewriting/

I'm not sure from your post what is currently happening or not happening so if you are still having an issue, let us know what happens if you use a certain rule.

Sorry Rachel, it wasn't very clear, the perils of writing at the end of the day having been trying to get it to work all afternoon. I've come at it a fresh this morning, scrapping and starting again, but I'm still stuck.

This is a Perch site, using the blog app that has various sections to it. I'd like to end up with the following url formats:

blog/section blog/section/post blog/year blog/year/month blog/tag

In my Perch settings I have: /blog/{sectionSlug}/{postSlug}

I have got the sections working, so that I can go to blog/section and the posts are listed, using this rule:

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

The links to the posts are showing as /blog/section/post, but don't load the post, just header, footer and sidebar. I have this rewrite rule for the posts:

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

I think if I can understand how to get these working I can sort the other ones out.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Make sure your more specific rules appear above the less specific rules.