The reason I joined was to find an answer, the technical stuff is way over my head.
You may have come to the wrong forum. Over here we force you to learn at least a little bit of the "technical stuff". (Not all of it. Right now there are at least four unanswered posts in Apache because I don't even understand the
question, let alone being prepared to make up an answer.)
I'm now trying to make sense of your posted code. Was that a direct cut-and-paste or is there stuff missing? Or did it come in via a third-party word processor that chewed up the original?
RewriteRule ^category(.*)/(.*)\.(php|js|css)$ {target here}
RewriteRule ^category(.*)(/images)(.*)$ {target here}
RewriteRule ^category/(.*/)*([^/\.]+)/([1-9][0-9]*)\.htm/?$ index.php?newid=$2&pg=$3[nocase]
RewriteRule ^category/(.*/)*([^/\.]+)/?$ index.php?newid=$2[nocase]
RewriteRule ^category/?.*$ {target here}
The form [nocase] is not technically wrong, but why expend the four extra bytes when [NC] does the same thing? Besides, it's wrong here-- not technically but functionally. You should never use [NC] in rewrites
except hotlink and similar rewrites, which are a special case. Can you work out what number 2^8 is? That's how many different URLs you have created by attaching the [NC] flag to an eight-letter word.
And, conversely, where did the rest of the flags go? Every RewriteRule needs at a minimum the [L] flag unless there is a clear and specific reason for leaving it out. And redirects need an explicit R=301 or they will default to 302.
Answer after some right-clicking: The flags are there, they just got eaten by the auto-linking-- which in turn means the flags will lead to some kind of error, because they're not delimited by a space. (I tested. It's "only" a 404, because the bracketed stuff will simply be read as part of the target.)
And about that auto-linking: There's a general WebmasterWorld rule about mentioning your own site by name. In some forums there are extra reasons for not doing so, and this is one of those forums. You noticed that anything in http: // turns into a clickable link. Well, that's no use in Apache because we need to see the exact text you typed. Use example.com and the text will remain visible.
If you read any three random threads in this forum you will find g1 or someone like him reading the riot act about using .* or .+ in non-final position. Notably in the first rule:
^category(.*)/(.*)\.(php|js|css)$
What happens: mod_rewrite meets the word "category" and then proceeds to capture happily to the very end of the request, because Regular Expressions are greedy by nature.
No, I do not know why RegEx terminology all has to do with food. "Flavors" instead of dialects, et cetera. It then sees that it was supposed to capture a slash, so it goes backward and backward until it comes to a slash, and then gulps up the whole remainder of the request. And
then it sees that it has to leave room for a period after its second capture, so it backtracks
again ...
And as for that
(.*/)*
in the third and fourth rules...
([^/\.]+)/
Huh. Did you get this piece from somewhere else? [^/]+/ is the standard pattern for capturing directories one at a time. And [^./] is even better because it stops before the final extension so you don't have to backtrack as much. Note that you don't have to escape the . inside of grouping brackets, since "anything that isn't a character" is obviously meaningless.
I kinda like that structure of the first rule with the $2.$3. But are those first two rules necessary at all? It sounds as if the rules were written to cope with pages containing relative links to subsidiary files. Since the pages themselves have been rewritten, not redirected, the browser "thinks" it is at
www.example.com/category/blahblah
and will therefore ask for supporting files at
www.example.com/category/etcetera
This means that every single request for an image or stylesheet has to be redirected. Surely it would be better to have the pages use absolute links with leading / so the request goes to the right physical location in the first place?
^category/(.*/)*([^/\.]+)/([1-9][0-9]*)\.htm/?
Oh, ouch. Oh, ouch. Please say you got this piece from somewhere else, and then we can jointly stomp on it without fear of offending anyone. Treated purely as a Regular Expression it's got more problems than I can count. It's the kind of thing I could use in my text editor on a single 800K document because if it takes too long I can always go clean the bathroom or something in the meantime. You don't want to put your server to that much work.
What we need you to do is explain
in English* exactly what these last few rules are intended to do-- and what the potential requests will look like-- and then we can figure out how to make them more streamlined.
One thing in all rules is definitely right so make sure you don't change it: the leading anchor before "category". This tells the server that if the beginning of the URL isn't the word "category" --and the very very beginning isn't the letter "c"-- then stop right now and don't spend any more time on the rule.
* I don't mean "English, not German". I mean "in regular human language without trying to put it into Apache-speak or Regular Expressions" ;)