Results 1 to 3 of 3

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

  1. #1
    Join Date
    Mar 2010
    Thanked 0 Times in 0 Posts

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

    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

    or real life example would be this random site that i pulled from wordpress

    and when you click on each blog entry title it redirects to its own page with the title in the URL like so

    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


    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?

  2. #2
    Join Date
    Mar 2006
    Illinois, USA
    Thanked 690 Times in 678 Posts


    This is not possible using PHP. What you need is to actually request the page at that new "URL".
    Then using something called mod_rewrite, you can dynamically and seemlessly (read "magically") give the user a different page than what they requested.
    A simple example: the user requests 1.php, then your server sends them 2.php, BUT it still reads "1.php" in the URL bar.
    It's very confusing to use because the syntax is hard (regular expressions ["regex"]) and if that isn't enough, it's obviously hard to test because it just operates and you can't see why, but just the results.

    You'll find lots of tutorials on mod_rewrite: it's a module in apache. Of course then you will forward the raw URL (probably AS a 'get' variable like in your first post) and you can then use PHP to serve the right data.

    So you will use PHP (or any other serverside langauge), but AS IF you were just using the regular page.php?var=value links and NOT the fake URLs you are not able to use. Your server handles the forwarding (completely invisibly to the user), and you're done.

    Be warned, though, this can get very complex, but there's some good info out there if you do some reading to figure it out.

    If you want a cheap and easy way out and you feel more comfortable with PHP (though even in PHP it is fairly advanced) you can use mod_rewrite to effectively use PHP to do the process, though it gets slightly messy. I wrote a tutorial on this a while ago, so take a look here:

    Again, this may not be the "best" way, but it works (for me), and it's easier than figuring out all of the details of mod_rewrite, at least for someone with an advanced knowledge of PHP and a beginner's knowledge of .htaccess/mod_rewrite.

    In short what you are asking for is possible, but unfortunately very advanced and there's no way to make it easier. The best chance for that is finding an example/tutorial that does a very similar thing to what you want to accomplish and copying the syntax-- that shouldn't be too hard.

    The ideal outcome of this (for most people) is:

    Lots of tutorials reference that and even if the coding gets too complex, you can always take use PHP from there to continue the process.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2010
    Thanked 0 Times in 0 Posts

    Thumbs up Thank you for the quick reply

    Thank you so much for the quick reply, at least now I know what I'm searching for and I will begin reading your tutorial on it.

    Thank you


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts