PHP: Files that don't really exist

Discussion in 'Web Design and Development' started by rendezvouscp, Mar 18, 2006.

  1. rendezvouscp macrumors 68000

    Joined:
    Aug 20, 2003
    Location:
    Long Beach, California
    #1
    Hello. I'm fairly new to PHP (I've been learning PHP thanks to Practical PHP Programming), and I'm interested in learning about how to access files that don't really exist. For example, on my WordPress blog, the permalink structure doesn't really exist on the server, but you can still go to those urls and access files.

    I know that WP, and presumably most everything out there, uses mod_rewrite in the .htaccess file. However, I can't seem to figure out what they're doing, or what it's called. If anyone could point me in the right direction, that'd be great.

    Thanks in advance.
    -Chasen
     
  2. Coolnat2004 macrumors 6502

    Coolnat2004

    Joined:
    Jan 12, 2005
    #2
  3. rendezvouscp thread starter macrumors 68000

    Joined:
    Aug 20, 2003
    Location:
    Long Beach, California
    #3
    Thanks Coolnat2004 for the help, although I'm a little bit lost. I looked at those tutorials and tried it out, but can't seem to get it working.

    I don't know if I'm placing the .htaccess in the wrong directory or if I'm writing the rewrite rules incorrectly. My goal is to have a url like "http://labs.chasenlehara.com/flickr/index.php?type=archive&page=6" map to "http://labs.chasenlehara.com/flickr/archive/page/6/" so that the URLs are cleaner. I'm trying to put this into the .htaccess file:

    Code:
    RewriteEngine On
    RewriteBase /flickr/
    RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/ /index.php?type=$1&year=$2&month=$3&day=$4&ispage=$5&page=$6&id=$7
    
    All of the extra "holders" are for various other pages (basically I'm replicating Flickr's URLs on my own site).

    Any ideas? Thanks for taking the time. :)
    -Chasen
     
  4. Coolnat2004 macrumors 6502

    Coolnat2004

    Joined:
    Jan 12, 2005
    #4
    It looks like all of your holders are your problem. See, to match the pattern on the left, the URL must have all of the stated characters.

    So, a valid URL for your match would be:

    http://labs.chasenlehara.com/flickr/1/2/3/4/5/6/7/

    if I am not mistaken. If /flickr/ is a directory, I don't think you need the RewriteBase as long as the .htaccess file is placed in the directory itself. Also, in the second part you might want to enter the full URL just to avoid confusion, because it looks like right now you're trying to send it to http://labs.chasenlehara.com/index.php?etc

    In general.. this stuff is confusing, sometimes inconsistent, and frustrating. But, once you get it working it's smooth.
     
  5. rendezvouscp thread starter macrumors 68000

    Joined:
    Aug 20, 2003
    Location:
    Long Beach, California
    #5
    No kidding. I'm unsure which site actually got me to where I am (a combination, with a stroke of good luck, really), but I finally figured it out a day or so ago. Thanks again for the help.
    -Chasen
     
  6. Coolnat2004 macrumors 6502

    Coolnat2004

    Joined:
    Jan 12, 2005

Share This Page