The user friendly URLs should be hyphened, for example:
http://example.com/some-category/some-file
My inherited folder structure however, is pascal cased, therefore the rewritten URL should look like this:
http://example.com/SomeCategory/SomeFile.php
Note: The amount of words in a category or file name will vary, so don't expect consistency in that way. ex. http://example.com/some-long-category/file
.
Im wondering how to do this, with a general rewrite condition-rule pair for any category and file, using Apache's mod_rewrite.
You can test your rules here, without the need to setup an Apache server.
I decided that adding another answer for the updated question made most sense, since my original answer may be useful for someone and is a valid approach as the question was originally stated.
mod_rewrite, as I understand it, loops until the URL is not altered, so we should be able to use that to loop until every word is changed. Here's the code.
This part needs to be in your main server config, at root level or in the
<VirtualHost>
:Then this in your
.htaccess
:That should do it. Please try it and let me know results.
As discovered in the comments, there is a default limit of 10 iterations, which means ten words limit. If you need to match more than ten words then you can increase the
LimitInternalRecursion
directive as appropriate.Note: The many comments below are mostly concerned with testing and tweaking until it worked, which it does. Although it then turned out that bare directories need to be matched too. A problem for another day, and perhaps another question!