views:

18

answers:

2

So I have photographs.php, and there are also sections where it will be rewritten as photographs.php?cat=somecategory

Question is, in .htaccess how do I get these both to work as such

/photographs and /photographs/somecategory

so that the $_GET['cat'] variable will be = somecategory

A: 

/photographs/(.+) will need to redirect to photographs.php?cat=$1, while /photographs/? will just redirect to photographs.php. if you want to be clever, you can combine it and do it in one line and /photograph will just go to photographs.php?cat=[blank].

Detect
RewriteRule ^photographs/?$ photographs.php [L]RewriteRule ^photographs/(.+) photographs.php?cat=$1 [L,QSA]
wes
Its what i have, i wanted to see if there was a single line solution, thanks though!
wes
yea, to combine it, just make the second part optional, so it's something like /photographs/?(.+)?
Detect
A: 

First of all you must have the mod_rewrite module activated.

Here's what you need to add to your .htaccess file:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^photographs$ photographs.php [NC]
RewriteRule ^photographs/(.*)$ photographs.php?cat=$1 [NC]

Just some simple replace rules. You can find lots of info on the web about them.

Alin Purcaru