0

I am using PHP script to set up a website which sells book.

Let say my website is hosted at www.sell-book-example.com. I want to allow accessing to a book detail page by navigating to www.sell-book-example.com/book/2121.html where 2121 is the book id.

Keep in mind that book/2121.html should not exist in the document root of the web server.

As in I do not want to pre-create many book detail pages in a book folder.

I have checked some other website which are able to do that with PHP.

If anyone can provide me some sample or link, that would be great. Thank you.

Martin
  • 22,212
  • 11
  • 70
  • 132
  • 1
    http://stackoverflow.com/questions/5990240/redirect-all-html-extensions-to-php – ka_lin Jul 13 '16 at 13:15
  • http://corz.org/server/tricks/htaccess2.php – gre_gor Jul 13 '16 at 13:20
  • You want to be researching `mod_rewrite` if you are running your webserver on an Apache/ Linux system. That does exactly what you are looking for and there is a lot of information already about that on Stack Overflow. – Martin Jul 13 '16 at 14:02

1 Answers1

0

This approach is known as Dynamically generating of pages by php scripting.

You have to create a script.php file where your dynamic code will be scripted and from the url you have to catch the code and according to the code you have to generate the book detail page. All this should be done by scripting.

The url will be like these

www.sell-book-example.com/script.php?id=2121
www.sell-book-example.com/script.php?id=2122
www.sell-book-example.com/script.php?id=2123

This urls will not show in website. To make it pretty as you need like

www.sell-book-example.com/book/2121.html

You have to redirect in .htaccess file i.e. to map the urls.

For example if some one is trying to call www.sell-book- example.com/book/2121.html url than internally it will be call www.sell-book-example.com/script.php?id=2121 url and produces your book details page of 2121.

Ananta Prasad
  • 3,655
  • 3
  • 23
  • 35