So, I have a site http://example.com
and i have a db with articles and what not,
When the article id is http://example.com/article
, everything is fine, the rewrite is done correctly, but when the ID is is http://example.com/article-name
I get a 404.
This is the code:
.htaccess
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ index.php?ID=$1
RewriteRule ^c/([^/]+)?$ index.php?CAT=$1 [L,QSA]
RewriteRule ^topic/([^/]+)?$ index.php?topic=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
article.php
<?php
if (isset($_GET['ID'])) {
require_once 'con.php';
$ID = mysqli_real_escape_string($conn, $_GET['ID']);
$sql = "SELECT * FROM `blog_article` WHERE articleID = '$ID' ";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result);
if (mysqli_num_rows($result) == 0) {
header("Location: /");
}
else{
include 'article.php';
}
}
elseif (isset($_GET['CAT'])) {
include 'c.php';
}
elseif (isset($_GET['topic'])) {
include 't.php';
}
else {
include 'index_view.php';
}
?>