Custom URL with PHP

This is not so-related to PHP, not code anyhow. I just wanna ask.

As you know, with a PHP file, I can use :

http://somesite.com/viewpost.php?postid=15

By using $_GET['postid']

But what if I wanna make these links :

http://somesite.com/post/15

How ? Thanks everyone here. Thanks ! :)
You'll need to use the POST method instead. I haven't used PHP very much so I'm fuzzy on exactly how you do it, but if you google 'How to hide URL parameters PHP Post" I'm sure something will come up that is helpful.
You just change the "method" attribute of the "form" tag to POST and use $_POST exactly as you would $_GET.
What?? I think he's talking about the way this site's forum URL system works. Notice that clicking links is not posting to PHP scripts but going to urls such as http://www.cplusplus.com/forum/lounge/65861/
@LB : Yes, you made it clear.

I don't think I would need a PHP file in http://www.cplusplus.com/forum/lounge/65861/ LOL

I need how URL works.
When a new post is created, you would have to create a directory for it, and then put all of the replies as text files into that directory. Then, the page that shows all of the posts would simply have links to all of the directories of the posts, and the page to display posts (index.*** inside of the posts directory) would then display all of the text files in it's directory (with all the proper styling added of course).
You don't need a PHP file there because the server automatically chooses a file called "index" (on Apache, at least) if one exists, but the browser doesn't know (it's abstracted away by the server). If you go to http://cplusplus.com/forum/lounge/65861/index.html you'll get the thread as normal (usually with PHP it'd be index.php but I guess the admin here has set up PHP to parse HTML files as well as PHP files).
Last edited on
No need to create extra directories or $_POST. $_POST is used to submit a request to the server. $_GET is used to request parameters append to the URL.

As chrisname suggest, you need to let your server know to use some file as the base. This is done in the .htaccess file.

Read here for more information.
http://corz.org/serv/tricks/htaccess2.php

Now there is two ways to handling this in PHP. The clean and better way is to reconstruct the URL, subtract the base domain, and then parse the remaining URL. This is what I would do because you build a more robust system as opposed to always editing your .htaccess file.

The other way is to just use .htaccess file and use the $_GET method to request the parameters.

Google htaccess url rewrite for more information.
Topic archived. No new replies allowed.