skip to Main Content

I have problem with SEO links. The Issue is that i would like to open an Clean SEO link to reach any article in my database, while simultaneously naming it in this format:

website.com/category/id/title

The problem is, that the data in question is also being fetched from a database, so its all dynamic.

This is the "a" tag that pushes sends me to my web page by the name article.

<p class="readmore">
 <a href="article?category=<?php echo $ArtCat; ?>&artid=<?php echo $ArtID; ?>&title=<?php echo $dashedTitle; ?>">Read More</a>
</p>

I would like for it to be like this, but when i change it to that, it doesnt move on to the next page as expected because the variables aren’t defined.

<a href="article/<?php echo $ArtCat; ?>/<?php echo $ArtID; ?>/<?php echo $dashedTitle; ?>">Read More</a>

This is whats on article.php

<?php
    echo "Article Category: " . $_GET['category'];
    echo "<br>";
    echo "Article ID: " . $_GET['artid'];
    echo "<br>";
    echo "Article Title: " . $_GET['title'];
    echo "<br>";
?>

my .htaccess


RewriteRule ^article/([0-9a-zA-Z_-]+)/([0-9]+)/([0-9a-zA-Z_-]+)$ article.php?category=$1&artid=$2&title=$3

2

Answers


  1. You need to start in your .htaccess the RewriteEngine, otherwise the RewriteRule won’t work.

    RewriteEngine on

    This code needs to stand before your RewriteRule.

    Login or Signup to reply.
  2. If I don’t missunderstand you in "it doesnt move on to the next page as expected because the variables aren’t defined.", the variables $ArtCat, $ArtID and $dashedTitle are not defined in:

    <a href="article/<?php echo $ArtCat; ?>/<?php echo $ArtID; ?>/<?php echo $dashedTitle; ?>">Read More</a>
    

    You are trying to access index.php which contains the <a> code to redirect user to article.php, am I right? The variables must be defined in the index.php or include into it. Maybe you have some code in index.php:

    <?php
    // include some files
    // query some database
    // some code
    ?>
    <a href="article/<?php echo $ArtCat; ?>/<?php echo $ArtID; ?>/<?php echo $dashedTitle; ?>">Read More</a>
    

    Not defined vars means you don’t have $ArtCat = "article-category-name" and none of other vars you request in <a href>

    If the code contains such attribution "=":

    1. Check for typos;
    2. If happens in // include some files (the code belongs to another file but it is included), make sure included are being well included; try require instead, log/echo the vars to be sure;
    3. If happens in // query some database, try some logs (or var_dumps) to check if databases results are not coming null values;

    If the attribution happens // some code check if the variables are not being defined inside functions.

    <?php
    function something ()
    {
        $ArtCat = "article-category-name";
        ...
    }
    something();
    echo $ArtCat; // Here $ArtCat it's not defined
     
    function somethingElse ()
    {
        $ArtCat = "article-category-name";
        ... // the other vars
        return [ $ArtCat, /* the other vars */ ];
    }
    somethingElse();
    echo $ArtCat; // Here $ArtCat it's not defined
    

    If the values of vars come from $_REQUEST, make sure they’re not coming null.
    If the values of vars come from environment vars, try echoing before and check if php runs in same scope they are defined.

    Maybe some more details can help me to help you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search