I'm making a simple blog for my portfolio for school. If I click on a link to show a blogpost, my url is domain.com/post?post_link=First-Post I've read a hunderds of SO items about changing this url, but nothing works for me...
I hope that anyone see what is the problem and give a solution
I have 3 files, blog.php(Here are all the posts showed), post.php(Here is one blogpost showed, based on post tiltle from page before) and a .htaccess file.
My blog.php:
<form method="GET" action="post.php">
<input type="hidden" name="post_link" value="<?php echo $post_link;?>">
<input type="submit" name="">
</form>
My post.php:
$post_link = $_GET["post_link"];
$sql = "SELECT * FROM blogposts WHERE post_link='$post_link'";
$result = mysqli_query($conn, $sql);
if ($result) {
while ($row = mysqli_fetch_array($result)) {
$post_link = $row["post_link"];
}
echo $post_link;
}
My .htaccess file:
Options FollowSymLinks
RewriteEngine On
RewriteRule ^post/([0-9a-zA-Z]+)$ post.php?post_link=$1
RewriteRule ^post/([0-9a-zA-Z]+)/ post.php?post_link=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
In addition to rewriting the url, everything works fine, like showing the posts and showing a single post
In blog.php, my input type hidden value is correct.
Please help..
Daniël
Change your action to just post
<form method="GET" action="post">
The resulting URL should be localhost/takast/post?post_link=First-Post
This Rule will then match this, but you need to keep the querystring [QSA]
.
Complete .htaccess:
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [QSA]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.