Forum Moderators: phranque

Message Too Old, No Replies

Accessing Virtual Dynamic Content

How does one access folders and files that do not really exist?

         

Komodo_Tale

12:46 am on Jan 18, 2007 (gmt 0)

10+ Year Member



I’m not sure how to word this properly, but the general question is how can one create virtual folders and access content dynamically within?

As an example, lets say you have a web site where each member accesses his or her home page by typing http://www.example.com/membername, ‘membername’ being the user name of each member. It would be easy enough to create each directory and to populate it with the required template documents (like index.html), but that would consume disk space and file quantity limitations. How con one design a website so that users may access a file in a directory that does not exist physically except as information in a database?

[edited by: encyclo at 11:46 pm (utc) on Jan. 18, 2007]
[edit reason] switched to example.com [/edit]

Komodo_Tale

2:15 am on Jan 18, 2007 (gmt 0)

10+ Year Member



WordPress blog content is a perfect example of this, by the way.

phranque

5:23 am on Jan 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



if you are using apache you could probably solve this with the rewrite module, possibly using a rewrite map.
[httpd.apache.org...]

rocknbil

8:26 am on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



^ ^ I agree, once you discover mod_rewrite it will be your new best friend. :-)

Komodo_Tale

7:11 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



I am more than a little familiar with mod_rewrite, though not near being an expert. Here is what WordPress has in mod_rewrite:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

That's it.

I think I am looking for something more.

phranque

11:14 pm on Jan 18, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i think wordpress is doing this internally, within the script, using aliases for pages.

lammert

5:58 am on Jan 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, the new versions of WordPress handle it internally, older versions (upto 1.2 at least) generated explicit codes to cut and paste in your .htaccess file. The code pasted above translates as "If the requested URL is not an existing file, nor an existing directory, pass it to index.php to process".

rocknbil

8:00 pm on Jan 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is almost exactly what I am using in mod_rewrite.

I think I am looking for something more.

By this I am guessing you mean you need it to differentiate between your site files and member pseudo-directories, correct?

In the above example, how this would work depends on index.php. This is one way you could approach it: since you will most likely have these members in a database, you should also record the member's "site URL:"

rec_id¦fname¦lname¦email¦site_url¦ . . . .

Then in index.php, before it looks up any site pages, first parse the path info and see if it matches on a site_url. Perl example:

http://www.example.com/MemberName

@paths = split(/\//,$ENV{PATH_INFO});
$last = pop(@paths); # Get the text after last /, "MemberName"

$select = qq¦select * from members where site_url = '$last'¦;

If the record is found, output the page. If not, index.php goes on and does whatever it does for other site files.

You will have to do something a little more complex if you offer multiple pages on this member directory, but this is one way to approach the problem.