This one has me stuck so I am hoping someone will be able to point me in right direction.
I have a database keeping all my posts which is called blog_posts_content. I then have a viewpost.php file which requests the post content matching the postSlug with a get request on the "id" as seen below:
<?php require($_SERVER['DOCUMENT_ROOT'] . '/includes/config.php');
$stmt = $db->prepare('SELECT * FROM blog_posts_content WHERE postSlug = :postSlug');
$stmt->execute(array(':postSlug' => $_GET['id']));
$row = $stmt->fetch();
//if post does not exists redirect user.
if($row['postID'] == ''){
header('Location: ./');
exit;
}
?>
Here is an example postSlug in the database ->
https://website.co.uk/testfolder/viewpost.php?type=services&category=webdesign&id=postname
I'm then trying to get this showing as
https://website.co.uk/testfolder/services/webdesign/postname
So far I have this htaccess file within my testfolder
RewriteEngine On
RewriteBase /testingfolder/
RewriteRule ^([^/]+)/([^/]+)/?$ catpost.php?category=$1&id=$2 [L]
RewriteRule ^a-(.*)-(.*)$ archives.php?month=$1&year=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ viewpost.php?type=$1&category=$2&id=$3 [QSA,L]
The testfolder includes the following files:
index viewpost catpost
So I am treating index.php as the home page ofcourse, the viewpost the request the post content and then catpost to show categories.
Now I hope I have detailed the background enough so now to the issue.
The above does not show the page so if im on index and click the link with the slug outlined above I get redirected back to the index page as per the php request.
If i just use this htaccess and just have the postSlug as the postname then I can get the post to show
RewriteEngine On
RewriteBase /testfolder/
RewriteRule ^category/(.*)$ catpost.php?id=$1 [L]
RewriteRule ^a-(.*)-(.*)$ archives.php?month=$1&year=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
However, with that my url ends up as
https://website/testfolder/postname
I'm questioning whether its the php request or the htaccess rules.
Any help on this would be huge as I'm pulling out my hair trying to undertand this!.
Aucun commentaire:
Enregistrer un commentaire