In php I have a script, that I use mod_rewrite to redirect all calls in a particular url. For example the mod rewrite rule is something like:
RewriteCond %{DOCUMENT_ROOT}/articles/$1 !-f
RewriteRule ^/articles/(.+)$ /articles/index.php [L]
Then my index.php script splits the url into its components and based on the components performs a particular function.
My problem is figuring out how to make the script 404 when people add additional subfolders to the URL. For example, if I have a url like this:
http://www.example.com/part/blue-widget/
My script will show the blue-widget page. Now if someone changes the url to read:
http://www.example.com/part/blue-widget/another_dir/
The script will still show the blue-widget page using this new URL. What I would like is for the script to instead issue a 404 error. I could have each function check for the amount of components in the URL and if its the right amount, show the content, otherwise issue a 404, but am not sure this is the best way to do it.
Depends on how the code which loads each page works, surely? eg, If each folder is a parameter in a function (like a lot of frameworks), you could compare the amount of folders against the amount of input parameters the function has?
EDIT: Will something like this do?
If you have a set of known parts, you could do: