0

So, I'm a little new to PHP and was wondering if someone could please give me a simple yet indepth answer on the problem I am having..

Lets take a forum like such for example. When a user creates a new thread how does the site create a new page (their thread)? Usually, the URL will end up looking like http://www.(sitename).com/forum/77375 <- Post ID I assume. How would I make such a thing?

I have a site which requires users to submit an article and currently I have made it so the article information is sent to a database. Now I need to make it so a new page is made with a unique URL with their article on it.

I am using PHP with MySqli - Help is much appreciated :)

Kukri
  • 1
  • Welcome to Stack Overflow! This question is a little short on information. Can you share what you have tried, and what problems you have run into? Please read [How to ask questions on StackOverflow](http://stackoverflow.com/help/how-to-ask) – Jay Blanchard Apr 22 '15 at 16:50
  • you can easily achieve this using .htaccess. – Hardy Mathew Apr 22 '15 at 16:52
  • Currently I have not tried anything, I have no idea how to approach such a task nor know what exactly to search, sorry :( Thanks for the welcome! – Kukri Apr 22 '15 at 16:52

2 Answers2

1

When you see SEO friendly URL like that, the site isn't (or at least shouldn't) be making an actually file with that post id. The site is doing a url rewrite. Basically it will take a URL such as http://www.sitename.com/forum and regardless of what comes after that, always load the same file (lets say it's called forum.php. It will then take the rest of the url, and change that into a query string.

So it will basically rewrite:

http://www.sitename.com/forum/123456

to be:

http://www.sitename.com/forum.php?thread_id=123456

Which the forum.php file can then get the data from the query string and know to pull the forum posts for the thread with the id of 123456

Here's a post with some more info: URL rewriting with PHP

Community
  • 1
  • 1
cwurtz
  • 3,177
  • 1
  • 15
  • 15
0
     RewriteEngine on

    # Not for real file or directory
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    # for category-1/ and all like xxxxx-xxx-nnn
    RewriteRule ^([^/]+-\d+)/?$ /index.php?page=category&category_name=$1 [L]

    # for contact/ or about/ or other/
    RewriteRule ^([^/]+)/$ /index.php?page=$1 [L]

so you can get something like as below :

http://www.example.com/index.php?page=Movie&movie_name=anyMovie - > http://www.example.com/anyMovie/

Hardy Mathew
  • 684
  • 1
  • 6
  • 22