Apache URL Re-writing not functioning properly

前端 未结 12 1479
春和景丽
春和景丽 2021-01-17 21:31

I am trying to use apache-rewrite rule to convert the below URL:

http://localhost/foo/bar/news.php?id=24

Into this

12条回答
  •  抹茶落季
    2021-01-17 22:14

    Change the link:

    echo " ". substr($row['title'], 0,26)."
    

    to

    echo "".$row['title'].""
    

    That way, the link will go to news/$row['title'] instead of news.php?id=.... And now in the page DIRECOTORY/AID/news.php, you should get the id and check if it is a number OR text, and in case of text match it up with the $row['title'] and then load the page accordingly.

    Notes:

    1. This assumes that $row['title'] is unique across all other rows.
    2. The title does not contain non HTML content, in which case you will have to URL Escape those characters.

    If the title is not going to be unique then you should probably do news/{id}/{title} and then in rewrite it to DIRECTORY/AID/news.php?id={id}&title={title} and then you can base it off of the ID instead of the title.

    Hope that helps.

提交回复
热议问题