I am trying to re-organize my website, and while testing some changes to my mod_rewrites, am not getting the outcome I’d expect?!
In English, here is what I want…
If a user tries to go to the “Finance” section (pretty URL)…
http://local.debbie/finance/
…then I want them to be taken to a new “Finance Home Page”, which would be this file…
http://local.debbie/finance/index.php
However, if a user navigates to any other section (e.g. Legal, Management, etc)…
http://local.debbie/legal/
http://local.debbie/management/
…then my original mod_rewrite should kick in, and they would be taken here…
http://local.debbie/articles/index.php?section=legal
http://local.debbie/articles/index.php?section=management
(BTW, what my original code is trying to do, is this… Take a look at the Section the user clicked on, and send that to the “template” file at “articles/index.php” which in turn populates the “template” with all articles from the database related to that Section.)
Does that make sense so far?
So here is how I modified my mod_rewrite, thinking it would work…
#PRETTY: finance/
#UGLY: articles/index.php?section=finance
#Rewrite only if the request is not pointing to a real file (e.g. add-comment.php, index.php).
RewriteCond %{REQUEST_FILENAME} !-f
#New Code looking just for "Finance" section...
RewriteRule ^/finance/$ finance/index.php [L]
#Match any kind of Section. PHP will decide if it's valid or not.
RewriteRule (.+)/$ articles/index.php?section=$1 [L]
When I use that mod_rewrite, it is as if the new line I added doesn’t exist. As such, when you go to…
http://local.debbie/finance/
…you are taken to a page which lists all Finance Articles (old way) versus my new “Finance Home Page” which is a new “index.php” file located in my new “finance” directory in the Web Root.
It appears my [L] switch thingy - or whatever it is called - is not working?! :-/
Hope all of that makes sense?!
Sincerely,
Debbie