Here is my .htaccess file, it's in the / directory and is working. I want to remove .php extensions from my site. So, I use the following rule to do so. RewriteRule ^([^\.]+)$ $1.php [NC,L].
This works but I also want to redirect my blog articles which use dynamic links with this RewriteRule ^([^?]*) route.php?blog=$1 these blogs pull an ID from a database and embed it into the URL and this works correctly.
My issue is that when I add the first paragraph code to remove .php extensions my blog redirect stops working. Below I will add my PHP code, for review in case I've done something wrong.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) route.php?blog=$1
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Error Documents
#ErrorDocument 404 /error_404.php
#ErrorDocument 403 /error_403.php
<?php
// open database //
include($_SERVER['DOCUMENT_ROOT']."/config.php");
$blog = explode("/",$_REQUEST['blog']);
$months = array('','January','Feburary','March','April','May','June','July','August','September','October','November','December');
switch(count($blog))
{
case 3 : {
if($blog[0]=="blog")
{
if(intval($blog[2]) > 0)
{
// get selected blog
$sql = "select * from articles a, categories c where a.cat = c.catid and a.id = '".$blog[2]."' limit 0,1";
$res = $db->query($sql);
$rowcount = $res->num_rows;
if($rowcount > 0)
{
$id = $blog[2];
$blog = mysqli_fetch_assoc($res);
include($doc_path."/blog-single.php");
}
}
}
} break;
}
blog-single.php
<?php
$sql = "select * from categories c, articles a, relatedposts r where r.related_blog = ".$blog['id']." and a.id = r.related_post and c.catid = a.cat order by a.datetime";
$rows = $db->query($sql);
$found = $rows->num_rows;
if($found > 0)
{
?>