how to display the title of page in that pages specific URL/link?

how to display the title of page in that pages specific URL/link?

how to display the title of page in that pages specific URL/link?

Question to me :

Hi, I’m new to PHP and I took on the challenge to build a simple blog using PHP that is similar to wordpress.
My question is how can I display the title of the entry in the URL of that specific entry page like for example
www.example.com/hello-world
or real life example would be this random site that i pulled from wordpress
http://nurse.wordpress.com/
and when you click on each blog entry title it redirects to its own page with the title in the URL like so
http://nurse.wordpress.com/2010/03/21/i-think-the-word-youre-looking-for-is-possible/
and the title of entry that i clicked on the main page is ” I think the word youre looking for is possible”
I hope you understand what i m trying to acheive, its really complicated to explain when I m new to PHP.
My blog script consists of PHP with mysqel and i can get the blog running perfectly except when i click on the entires of my blog the URL is similar to

/view.php?$id=246

My goal is to change “…./view.php?$id=246” into the title of the entry for example “…./hello-world”
Is it possible to hide “view.php?$id=246” and change it to title of entry?
Can you please help me to solve this problem?

Here we go..

Method 1:

index.php?page=1
index.php?page=2
index.php?page=3

can be changed to

index1.html
index2.html
index3.html

[codesyntax lang=”php”]

RewriteEngine on
RewriteRule ^index(.*)\.html$ /index.php?&page=$1/ [L]

[/codesyntax]

This is the simplest example where apache identifies $1 = number of pages and rewrites here (.*)

i.e. RewriteEngine to parse the URLs of the form indexX.html and send the request to the server as index.php?page=X.

this will not act as a redirection when the page is visited by visitors or crawlers. For all they know, this is a static HTML page.

Now suppose if you used index.php?page=1 you can now use page1.html. And the page value in the URL will still be retrieved in PHP using the same method – $HTTP_GET_VARS[‘page’]

the page will still be accessible through the query string form (index.php?page=1) but if you don’t link to them, no one will know

Now you would probably put that line in a while loop to retrieve all the pages from a table.

[codesyntax lang=”php”]

<?php

echo "<a href='index.php?page=".$PageID."'>".$PageTitle."</a>";

?>

[/codesyntax]

Now, you’re simply going to form the URL

[codesyntax lang=”php”]

<?php

echo "<a href='index".$PageID.".html'>".$PageTitle."</a>";

?>

[/codesyntax]

Now dealing with title is also much easy as page ID.

suppose general link is

index.php?page=1&title=hello-world

This can be done with rewrite rule

[codesyntax lang=”php”]

RewriteEngine on

RewriteRule ^index(.*)/(.*)\.html$ /index.php?page=$1&title=$2/ [L]

[/codesyntax]

output would be

index1/hello-world.html

its easy NjOy!

abhijeet on Facebookabhijeet on Linkedinabhijeet on Twitter
abhijeet
abhijeet
Abhijeet specializes in developing software. A full-stack developer and Entrepreneur, he takes an idea and crafts it into a beautiful product - front to back. He develops on the LAMP Stack (PHP, MVC, Web API, Perl, Python, Azure, AWS, Google Cloud) and utilizes AngularJS and Angular Material for a structured client. Abhijeet is a self-starter with experience working in remote, agile environments mainly focusing on the security constraints. This is the developer, Project Manager and Consultant you are looking for.