Forum

Thread tagged as: Question, Problem, Blog

Outputting clean blog URLs

Can someone take me through the process of getting clean blog post URLs

I've got things working on the default setting but I'm doing the following and getting errors:

  1. htaccess file

Note my /blog/ folder containing the blog post template is at /posts/ otherwise my blog page won't load due to filename extension stripping out.

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.+)$ $1.php [L,QSA]

redirect html pages to the root domain

RewriteRule ^index.html$ / [NC,R,L]

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

  1. Changing the Blog post page path in the CMS settings to:

/posts/{postSlug}

  1. I'm calling the blog post in the /posts/post.php file thus:

    <div class="post"> <?php perch_blog_post(perch_get('s')); ?>

            <div class="meta">
                <div class="cats">
                    <?php perch_blog_post_categories(perch_get('s')); ?>
                </div>
                <div class="tags">
                    <?php perch_blog_post_tags(perch_get('s')); ?>
                </div>
            </div>
    
    
    
        </div>
    
  2. I'm calling the blog post with this code:

<?php perch_blog_section('blog'); ?> <?php perch_blog_custom(array( 'section' => 'blog', 'template' => 'post_in_list.html', ));?>

The URLs I'm getting are:

https://www.website.com/posts/a-test-blog-post

So I believe it's looking in the correct folder for the blog template being /posts/ but I get a 404 error.

Andrew Areoff

Andrew Areoff 0 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

There is a video in the documentation which explains how to do this, you can find it here:

https://docs.grabaperch.com/video/v/simple-url-rewriting/

Typo in your htaccess

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

Should be:

RewriteRule ^posts/ ... etc

That works brilliantly now guys. Thanks very much!