wesside
wesside

Reputation: 5740

rewrite php file in htaccess with our without query string

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

Upvotes: 0

Views: 237

Answers (2)

Alin P.
Alin P.

Reputation: 44346

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.

Upvotes: 0

Detect
Detect

Reputation: 2069

/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].

Upvotes: 1

Related Questions