virtual folders?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

virtual folders?

Post by qads »

hi,
i am working on a project where users can create their resume/cv, the client wants the script to create a new folder for every CV/resume the users create, which is no problem, but it may be a problem when there are few K users.

so, i was wondering if there is a way to create "virtual folders", which means (in my head heh), that if a user access www.domain.com/cv/[i]username[/i], server would "pretend" the folder does exists, and it would load username's resume, i could find out who the user is by checking out the url typed in, and loading the content from the database :D.

so, how would i go about this? can it be done with a .htaccess file? the hosting is shared so that counts out the mod_rewrite(never used it) etc.

the client is not bothered either way, i just want to be efficient :P.

thanks
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

that is the perfect solution mark but dont think there are many hosts who offer apache2, especially on shared server plan, so i can't use it cos of 'AcceptPathInfo', which is only available on apache2+ :? (my client hast even got a domain yet 8O).


i did try to force apache to accept file names without .ext and parse them (forcetype, addtype), but nope, it dont like that.

any other ideas? :roll:
thanks
Last edited by qads on Fri May 14, 2004 6:25 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what about mod_rewrite then?
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

never used it :?, do i just put it in a htaccess file? cos thats what i did, found it at the link mark posted, in the comments, didnt work....prolly cos i was doing it wrong or the code was wrong.
mod_rewrite wrote: RewriteEngine On
RewriteRule ^/(articles)/(.*)$ /$1.php
[L,PT,E=PATH_INFO:/$2]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I haven't used it yet myself, but it sounds perfect for this situation:
http://httpd.apache.org/docs/mod/mod_rewrite.html
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

big doc 8O, gona have to read it tomrrow or soemthing, working on something atm :P.

thanks :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

alternately.. you may be able to write a specialized 404 handler if you can't get mod_rewrite installed on the host..
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

yea, might just have to do that, if i am right, your talking about having a 404 page which checks what page the user was looking for, and redirects them to the right page after getting the values from the url?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

exactly.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

this might be the only quick (and dirty) way of doing it, i am not sure about the server this site will be hosted on, so i might aswell go with this, atleast its easier to fix if something goes wrong :P.

thanks for idea :D.
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

If the server lets you, you can turn on mod_rewrite in an .htaccess file. It's really, really easy to set up. In your .htaccess file in the top of your document root, put the following:

rewriteengine on
rewriterule /cv(.*) /cv_script.php

that's it! Then, in your cv_script.php file you can look at the $_SERVER["REQUEST_URI"] variable, which will hold the /cv/dave420 URL, as opposed to /cv_script.php. Using the referrer, you can preg_match or split it to retrieve the username.

Of course, this all requires mod_rewrite installed and enabled on your web server.
sandralex
Forum Newbie
Posts: 1
Joined: Fri May 28, 2004 3:45 pm

Try this

Post by sandralex »

qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

got it working :D, it only works on linux, i can live with that :D.

thank you everyone.
Post Reply