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
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.
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:You are trying to access
index.php
which contains the<a>
code to redirect user toarticle.php
, am I right? The variables must be defined in theindex.php
or include into it. Maybe you have some code inindex.php
: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 "
=
":// include some files
(the code belongs to another file but it is included), make sure included are being well included; tryrequire
instead, log/echo the vars to be sure;// query some database
, try some logs (orvar_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.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.