Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rendezvouscp

macrumors 68000
Original poster
Aug 20, 2003
1,526
0
Long Beach, California
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
 

Coolnat2004

macrumors 6502
Jan 12, 2005
479
4

rendezvouscp

macrumors 68000
Original poster
Aug 20, 2003
1,526
0
Long Beach, California
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
 

Coolnat2004

macrumors 6502
Jan 12, 2005
479
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.
 

rendezvouscp

macrumors 68000
Original poster
Aug 20, 2003
1,526
0
Long Beach, California
Coolnat2004 said:
In general.. this stuff is confusing, sometimes inconsistent, and frustrating. But, once you get it working it's smooth.

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.