folder/892384 instead of folder/?892384 or folder/?id=892384

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

folder/892384 instead of folder/?892384 or folder/?id=892384

Post by phice »

I'm making a small, custom-built forum for my website. I want each thread to have a real address, or atleast look like it is. I know how to do the ?892384 and ?id=892384 (who doesn't ;)). But, I want it to have a folder/892384, but not have to create that file each and every time a post is posted.

Any ideas? If you need any more information, please ask me.
Image Image
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

i.e.

Code: Select all

<Location /board>
    SetHandler application/x-httpd-php
    Order allow,deny
    Allow from all
</Location>
any request on /php will be handled through php.
Having a php-script file forum in that directory a request for http://your.host/board/forum/892384 will result in

Code: Select all

$_SERVER&#1111;'SCRIPT_NAME'] == '/board/forum'
$_SERVER&#1111;'PATH_INFO'] == '/892384'
don't know wether this is clean or not - but it works ;)
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Yes, you would be using htaccess simlar to php.net to tell your server

"if a real file is not found, and it's an integer, search for the # post"


look at the bottom of http://www.php.net/urlhowto.php
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

i do something similar to this on my forums. my requested uri's look like this:

Code: Select all

/forum/thread/######
then i use Apache's Rewrite Module to translate this to a page. here is what my conditions look like

Code: Select all

RewriteRule ^forum/thread/(&#1111;0-9]+)	/forum/thread.php?$1
so the above uri translates to this:

Code: Select all

/forum/thread.php?######
then in the first line of thread.php I have this

Code: Select all

$tid = $_SERVER&#1111;'argv']&#1111;0];
at that point i have my thread id and can use it as i wish. hope this helps and would be willing to help you more in getting your application to work.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

erm, it's still not working (way delayed response. ;D)

I tried the above, mydimension, and still only getting a 404. Should the htaccess code be placed in a certain folder? I tried the /forum folder, and the default folder /.
Image Image
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Please correct me if I'm wrong but by the looks of things this can't be done without access to the Apache config file... which means if you don't run your own server or if your host won't allow you to edit the config file then there's no way of getting this to work?

8O
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I'm just testing this on my home server for right now.
Image Image
Post Reply