Forum

Thread tagged as: Question, Blog

SEO Friendly Blog URL's

Is there a way to remove "post.php?s=" from your url's?

I know you can change the "blog post page path" from the admin settings, however I would imagine by removing post.php the blog post won't display properly or at all.

What would be the best way to accomplish this?

Nick Santini

Nick Santini 0 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

That works but now I have a new problem. I had a sitemap set up for my blog that requires php. After changing the .htacess the sitemap no longer displays properly.

/blog/blog-sitemap.php

<?php
    header('Content-type: application/xml');
    include('../perch/runtime.php');
    perch_blog_custom(array(
        'template'=>'blog-sitemap.html',
        'count' => 6000
    ));
?>

blog-sitemap.html

<perch:before><?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
</perch:before>
<url>
    <loc>https://example.com<perch:blog id="postURL"/></loc>
</url>
<perch:after>
</urlset>
</perch:after>

Is there a rewrite that will make sure that https://example.com/blog/blog-sitemap has the .php?

Drew McLellan

Drew McLellan 2638 points
Perch Support

When you say it doesn't display properly, what happens?

Before the rewrite it would appear as a standard xml tree. After the rewrite it displays what the default post.php would display when there isn't a specific post to display.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have a rewrite rule in place for the sitemap?

No. Thats why I thought there was possibly a way to make sure that /blog/blog-sitemap rewrites to /blog/blog-sitemap.php and actual blog posts like /blog/example-blog-post.php rewrite to /blog/example-blog-post

I have no idea what the actual rewrite rules would be though.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you currently have?

The rewrite rule that is effecting the sitemap is:

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

Drew McLellan 2638 points
Perch Support

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

That worked. You're the man, Drew!