dcblogdev / dcblogcomments

2 stars 0 forks source link

creating-a-blog-from-scratch-with-php-part-2-seo-urls #14

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Creating a blog from scratch with PHP - Part 2 SEO URLS - DC Blog

This tutorial will cover adding SEO urls to the existing blog, This part will cover using (SEO) s...

https://dcblog.dev/creating-a-blog-from-scratch-with-php-part-2-seo-urls

avnibania commented 4 years ago

Hi!

Can you help me with it? After setting up the stuff, and would like click on the link it reloads and load up the index.php... :( What you think, what did i made wrong?

shoaib0205 commented 4 years ago

viewpost.php?id= is not removing from URL via .htaccess file...... what can i do now????

dcblogdev commented 4 years ago

Hi!

Can you help me with it? After setting up the stuff, and would like click on the link it reloads and load up the index.php... :( What you think, what did i made wrong?

have you changed the links to have a slug?

the RewriteBase should reflect your folder structure ie if on a root domain it would be / or if in a folder called blog it would be blog

RewriteEngine On
RewriteBase /simpleblog-seo/

RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]
dcblogdev commented 4 years ago

viewpost.php?id= is not removing from URL via .htaccess file...... what can i do now????

the mod rewrite does not remove the old style URL but provides a cleaner more human friendly way to read URLs, your code should be changed so all links use the new style.

shoaib0205 commented 4 years ago

Slug is working well but .htaccess is not work properly i want to remove viewpost.php?id= from URL

Current URLs- http://bookmyessay.com/testau/subject-new http://bookmyessay.com/testau/subject-new/viewpost.php?id=Finance-Assignment-Help

.htaccess file- RewriteEngine On RewriteBase /simpleblog-seo/

RewriteCond %{REQUEST_FILENAME} !-d [NC] RewriteCond %{REQUEST_FILENAME} !-f [NC] RewriteRule ^(.*)$ viewpost.php?id=$1 [QSA,L]

please help me out :-)

dcblogdev commented 4 years ago

have you tried setting the RewriteBase to your folder RewriteBase /testau/

your second link should be

http://bookmyessay.com/testau/Finance-Assignment-Help

assuming Finance-Assignment-Help is the post slug.

shoaib0205 commented 4 years ago

yeah, everthing is working fine....

http://bookmyessay.com/testau/blog/blogs/what-are-the-ghostwriters-and-how-they-can-help-students-in-writing-assignments i want to remove blogs from the URL,

shoaib0205 commented 4 years ago

hey WORKING- https://www.bookmyessay.com.au/subject/net-compact-framework-assignment-help NOT WORKING- https://www.bookmyessay.com.au/subject/net-compact-framework-assignment-help/ can you suggest me?

tjbruce17594 commented 4 years ago

Hey! I've been following all the steps to the letter, but when I try to open a blog post, the url is a slug but it just takes me back to the index page.

https://tjbruce17594.com/blog/

dcblogdev commented 4 years ago

Just in case anyone else has this problem. .htaccess allows you to use friendly URLs but it does not change the link structure in your PHP files, you will need to update all links to use the slug versions of your urls.

vizaganand commented 4 years ago

"Just in case anyone else has this problem. .htaccess allows you to use friendly URLs but it does not change the link structure in your PHP files, you will need to update all links to use the slug versions of your urls."

I am also facing this problem. Can you explain how to update all links to use the slug versions of urls.

The issues are

1) when clicking on post title or read more, it is not going to the respective detailed post. 2) when i am trying to add post from admin, it is not saving without giving any error message.

The blog hosted at www.kambalainfotech.com/webdesigning-blog

Can you help

javadimoghadam commented 3 years ago

Hi dcblogdev, I have a problem. When I try to save the password in the database, no value is entered and surprisingly it is stored in a ' Null ' database. please help me

dcblogdev commented 3 years ago

Sounds like you may be using an old version of PHP where the password functionality is not support. Do you know what version you are using?

javadimoghadam commented 3 years ago

Dear dcblogdev , My PHP Version is 7.4.11

dcblogdev commented 3 years ago

that's odd it should definitely work on 7.4. When you say you save the password how are you doing it? I mean what does the query look like?

dcblogdev commented 3 years ago

The online demo is running on PHP 7.4 so I know it works there.

javadimoghadam commented 3 years ago

Dear @dcblogdev , I Solved My Problem (But after two week 😂) Just Change One Parameter In password_hash Function Just Change Algo Parameter to (algo : 2) Your Code :

$hashedpassword = $user->password_hash($password, PASSWORD_BCRYPT);

My Code :

$hashedpassword = $user->password_hash($password, 2);

And it Work ! , Password Saved on Database

dcblogdev commented 3 years ago

Maybe your server does not have that option installed? Thanks for documenting your solution for it 👍

avnibania commented 3 years ago

Hey , I hope you doin well! So my problem is when i update the post i get this : https://domain.com/blog/viewpost.php?id=- i have title but it gives just an -

Any idea? Thanks!

avnibania commented 3 years ago

Sorry i corrected the functions.php and now its work! But i get a new question! how can i place special charachters letters like á as a or é as e?

dcblogdev commented 3 years ago

I'd recommend avoiding special chars in urls but if you need them then this function will need updating:

function slug($text){ 

  // replace non letter or digits by -
  $text = preg_replace('~[^pLd]+~u', '-', $text);

  // trim
  $text = trim($text, '-');

  // transliterate
  $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

  // lowercase
  $text = strtolower($text);

  // remove unwanted characters
  $text = preg_replace('~[^-w]+~', '', $text);

  if (empty($text))
  {
    return 'n-a';
  }

  return $text;
}

maybe without using iconv?

avnibania commented 3 years ago

It is not working! Maybe i was not understandable, iam from Hungary, It is one of the most hardest language of the world. We have some words with speacial charachters like á or é or ő ! If i add a title as Általános Teszt (m: General Test) then i get the slug like this: domain.com/blog/viewpost.php?id=ltalnos-teszt but i want this domain.com/blog/viewpost.php?id=altalanos-teszt [from általános -> altalanos] Or did i failed something?

avnibania commented 3 years ago

btw, Thanks a lot! I really like your stuffs

dberadyn commented 2 years ago

I think people might have ran into problems from not having their apache mod rewrite set up properly on their server because I had this issue. It created the problems others complained of above. Following the instructions on this page might resolve issues should someone run into them.

<VirtualHost *:80> <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted

. . .

https://www.digitalocean.com/community/tutorials/how-to-rewrite-urls-with-mod_rewrite-for-apache-on-ubuntu-20-04

dberadyn commented 2 years ago

Also, I just noticed that the MySQL query needs to be updated with a request for the postSlug. That is another source of problems. I just had this issue after following your instructions on this page.

$stmt = $db->query('SELECT postID, postTitle, postSlug, postDesc, postDate FROM blog_posts ORDER BY postID DESC');