0

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.