How do you put dynamic pages after the url?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • proger
    New Member
    • Jan 2022
    • 1

    How do you put dynamic pages after the url?

    I am creating a website in PHP with articles, where articles can be added via a form. All data is stored in a MySQL database.

    First I made a separate page of each article, eg article1.html, article2.html, ... but then I got a lot of pages.

    Now I saw that on other websites the articles are behind the url, eg. https://mywebsite.com/article1

    I've tried searching the internet for how they do this, but I'm not sure how to look this up as I don't know what this technique is called.

    Do you know what this is called or how they do this?

    I had already found things about dynamically generated page and then put the url in the sitemap, but i don't know if this is the right way?
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    I am creating a website in PHP with articles, where articles can be added via a form. All data is stored in a MySQL database.

    First I made a separate page of each article, eg article1.html, article2.html, ... but then I got a lot of pages.

    Now I saw that on other websites the articles are behind the url, eg. https://mywebsite.com/article1

    I've tried searching the internet for how they do this, but I'm not sure how to look this up as I don't know what this technique is called.

    Do you know what this is called or how they do this?

    I had already found things about dynamically generated page and then put the url in the sitemap, but i don't know if this is the right way?
    You may be looking for path parameters or query parameters.

    Comment

    • GazMathias
      Recognized Expert New Member
      • Oct 2008
      • 228

      #3
      mod_rewrite

      Hi,

      I think you are referring to URL rewriting. In PHP it is common to make use of Apache's mod_rewrite for this functionality.

      I won't go into detail here as there are a great many tutorials that can explain it better than I can but a basic explanation of the simple implementation in your question would see a user visiting https://mywebsite.com/article1, but would be translated by the rewrite engine to https://mywebsite.com/index.php?articleid=article1.

      The index.php page would then interrogate the article parameter in the query string through $_GET['articleid'] and use it to query and render the article data from the database.

      This is an oversimplificat ion, as for for real-world scenarios you must consider secutity and validation. Most frameworks have handlers for parsing this type of parameter that take some care of such filtering for you.

      I hope that points you in the right direction.

      Gaz
      Last edited by GazMathias; Feb 14 '22, 11:10 AM. Reason: typo

      Comment

      Working...