In the past, I was working with URL’s with a “Section” and an “Article Slug” like this…
http://local.debbie/finance/articles/sequester-could-lead-to-more-start-ups
And I had this “permissive” mod_rewrite… (Thanks to the fine people here at SitePoint!!) :tup:
#RewriteRule ((.+)/)?articles/(.+)$ articles/article.php?section=$2&slug=$3 [L]
Stylistically, I like this type of mod_rewrite, because it allows most cases to fall through to my PHP script where I log and display a very specific Error Message (versus a generic 404 error).
Okay, so on to my current problem…
So now I am adding the concept of a “Sub-Section” to my website and thus URL.
New URL’s will look like this…
http://local.debbie/finance/economy/articles/sequester-could-lead-to-more-start-ups
I’m not sure how to modify the mod_rewrite above to give me a similar effect like I have now…
Honestly, I’m not sure what I’m looking for, but I guess I want it so that if either the “Section” or the “Sub-Section” is missing that instead of getting a “Page Not Found”, my mod_rewrite passes the “NULLs” and lets my PHP script decide what to do…
Make sense? :-/
Here is as far as I can get things…
RewriteRule ((.+)/)?((.+)/)articles/(.+)$ articles/article.php?one=$1&two=$2&three=$3&four=$4&five=$5 [L]
Here are the scenarios I get…
Scenario #1:
http://local.debbie/finance/economy/articles/sequester-could-lead-to-more-start-ups
one = finance/
two = finance
three = economy/
four = economy
five = sequester-could-lead-to-more-start-ups
This seems okay.
Scenario #2:
http://local.debbie//economy/articles/sequester-could-lead-to-more-start-ups
one =
two =
three = economy/
four = economy
five = sequester-could-lead-to-more-start-ups
This seems okay.
Scenario #3:
http://local.debbie/finance//articles/sequester-could-lead-to-more-start-ups
one =
two =
three = finance/
four = finance
five = sequester-could-lead-to-more-start-ups
I don’t like this “shifting” of variables
I would have expected…
one = finance/
two = finance
three =
four =
five = sequester-could-lead-to-more-start-ups
Scenario #4:
http://local.debbie///articles/sequester-could-lead-to-more-start-ups
Page Not Found
Not sure I like this either.
I would have expected…
one =
two =
three =
four =
five = sequester-could-lead-to-more-start-ups
With my current code, if either the “Section” or “Article Slug” is missing, things fall through to my PHP code so I can display/log a customized Error Messages.
So, with this new scenario, I would like it so that if either the “Section” or “Sub-Section” or “Article Slug” are missing, then control falls through to my PHP script so I can display/log customized Error Messages. (This should be doable in my mind?!)
Any ideas how to get this behavior?? :-/
Sincerely,
Debbie