Making URL with Parameters SEO Friendly

Hello all,

I have been following along with the PHP Novice To Ninja Book and using to build my own CMS.

I have implemented a simple Blog feature that lists all the blogs with links to the actual blogs: eg: https://www.room4studios.co.uk/blog/list contains links to https://www.room4studios.co.uk/blog/wholeblog?id=6 (those are live examples if you want to have a look)

So I need to somehow change it to https://www.room4studios.co.uk/blog/seo-friendly-url

Seemingly I want to link to the friendly url but behind the scenes actually serves the one with a parameters

I have been reading around about URL masking, mod-rewrites, canonical links and I’m confused about how to approach this, and would really appreciate if someone could take the time to explain a way forward.

Incase its useful my wholeblog function is :

    public function wholeblog() {
        $blog = $this->blogsTable->findById($_GET['id']);
$comments = $this->displayCommentsTable->findAllById($_GET['id']);
if (isset($_GET['commentid'])) {
            $comment2edit = $this->commentsTable->findById($_GET['commentid']);
        }
        $title = $blog->blogHeading;
        $metaDescription = $blog->metaDescription;
        $canonical = 'blog/wholeblog?id=' . $blog->id;
        $author = $this->authentication->getUser();
        return ['template' => 'blogwhole.html.php',
                'title' => $title,
                'metaDescription' => $metaDescription,
                'canonical' => $canonical,
                'variables' => [
                    'blog' => $blog,
                    'comments' => $comments,
                    'comment2edit' => $comment2edit ?? '',
                    'user' => $author, //previously 'userId' => $author->id ?? null,
                    ]
                ];		
    }

since “seo-friendly-url” is presumably unique, you’d find the blog article and comments by that string, rather than ID.

I could try that but presumably I’d still end up with an url along the lines of
https://www.room4studios.co.uk/blog/wholeblog?url=seo-friendly-url

It’s my understanding that i need to get rid or at least not display the ?url=

Well the server’s going to have to rewrite the URL silently with a rewriterule.

Any suggestions on how to achieve this silent rewrite rule?

Currently my htaccess is as described in the PHPNovice->Ninja book and redirects everything to index.php:

Blockquote
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [NC,L,QSA]

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.