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.

3
  • 1
    stackoverflow.com/questions/5990240/… Commented Jul 13, 2016 at 13:15
  • corz.org/server/tricks/htaccess2.php Commented Jul 13, 2016 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. Commented Jul 13, 2016 at 14:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.