'I want to make Blog Url of PHP seo friendly without using slug [closed]
I am developing a website in core php with custom cms. I am facing problem while making the blog url's seo friendly.
My Url is of this type and I want the url like websitename/blog/title If I fix it through htaccess file, that will be static because i want a single function which works for future blog posts as well. So Please Help me to solve this issue.
Solution 1:[1]
Make the specific blog title a $_GET value with htaccess
RewriteRule ^blog/([A-Za-z0-9-]+)/?$ /blogs.php?blog=$1 [NC,L]
then you can print the blogs out from the blog` id or title
Once that is set up you need to get the $_GET data from the blog table of the database in your blogpost.php script like so:
$sql ="SELECT * FROM blog_table WHERE title = ".$_GET['blog']." LIMIT 1";
$blog = mysqli_fetch_array(mysqli_query($sql));
echo '<h1>'.$blog['title'].'</h1>';
echo '<p>'.$blog['content'].'</p>';
obviously security needs to be thought about and prepared statements would be better.
Solution 2:[2]
You could try:-
RewriteEngine On
RewriteBase /
RewriteRule ^blogpost.php/(.+)(/?)$ /blogpost.php/?post_slug=$1 [NC,L]
# or slightly nicer would be to remove the `.php` thus:-
RewriteRule ^blogpost/(.+)(/?)$ /blogpost.php/?post_slug=$1 [NC,L]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
