views:

21

answers:

2

How should my .htaccess file look like if I want the following conditions to be met:

if page requested is /webcam/* then actually show /show.php and if page requested is /tag/* then actually show /tag.php

when searching on google for this, i only found how to meet one condition, but not two together.

Thanks,

A: 

Try this in the .htaccess file in your document root directory:

RewriteEngine on
RewriteRule ^webcam/ show.php
RewriteRule ^tag/ tag.php
Gumbo
That works great, I have another question.The file show.php receives an id parameter which i then take and pull out the correct content accordingly.Each ID also has a title, which I want to display as: /webcam/title-goes-here.What is the best approach PHP-wise regarding this issue, because using the $_server['request_uri'] to get the title and then search the id by it is not a good approach i assume..
Jim
@Jim: You can use mod_rewrite and extract some parts using regular expressions, for example `RewriteRule ^webcam/([^/]+)$ show.php?title=$1` for the title.
Gumbo
Oh, that's quite cool.. but that will allow me to attach the title to the 'title' parameter, how do i go abouts pulling the ID though? will i have to include it in the url? /webcam/123/title-goes-here if i want the php script to have access to it?
Jim
@Jim: Yes, your URL will need to include that ID; otherwise you will need to have unique titles. `RewriteRule ^webcam/([0-9]+)/[^/]+$ show.php?id=$1`
Gumbo
A: 

I see what you did there, (don't forget to give some free credits to the stackoverflow.com community)

sathia
oh, no it's not porn related, sorry :)
Jim