But it doesn't work. Server ignores the rule and just serves /articles/category/yyyy/mm/dd/article.php file which does exist but it should be served included from serve.php (because of navigation, layout, etc).
Before trying this I was using local .htaccess in /articles directory but then I had two other issues:
I'm not an htaccess expert, so when making a custom framework, I use a mix of simple htaccess rules and some tricks with the $_SERVER['REQUEST_URI'] variable.
Thus, all the required parameters will be inside the $req array, and I can make the conditions/decisions based on those values. I don't consider this as a good method as I should take care of the order of variables in the url. The advantage(from my experience) of this rule is, I'll get the execution control in the desired file, even if there is some missing slashes or parameters in the requested url (which helps me to make a custom "did you mean" option). Further, this simple rules won't interfere with any other rules like (no-www) in any case.
Just wait for a better solution, if the above is not satisfactory.
PS: After all, I haven't used more than one serving files yet, so I use
I’m also not at all an htaccess expert but CMS Made Simple, with which I’m working frequently, has a default htaccess for pretty URLs with the following content (the rule at the bottom is for the actual URL rewrite):
Code:
<IfModule mod_rewrite.c>
RewriteEngine on
#
#Sub-dir e.g: /cmsms/
RewriteBase /
#
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
And I just include the no-www rule after the RewriteBase command (or whatever it’s called) and before the other rewrite conditions so the outcome is this:
Code:
<IfModule mod_rewrite.c>
RewriteEngine on
#
#Sub-dir e.g: /cmsms/
RewriteBase /
#
# no www rewrite rule
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
#
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
I see. That is similar to what I was trying to do, only with a quirk.
On my server actual files requested do exist but they need to be rewritten because they are just the articles with the basic formatting -- no header, footer, or navigation. They get served by serve.php which constructs the actual page (keywords, title, xhtml, navigation, etc) from mysql database and the file requested.
The fact that I can't figure out the proper .htaccess really puzzles me.