lucy24 - 7:51 pm on Apr 19, 2013 (gmt 0) [edited by: phranque at 12:57 am (utc) on Apr 21, 2013]
mod's note: sorry for the slice and dice. this is the explanation provided by lucy24 to which john refers above.
System: The following message was cut out of thread at: http://www.webmasterworld.com/apache/4566749.htm [webmasterworld.com] by phranque - 5:49 pm on Apr 20, 2013 (utc -7)
The site is a php mysql database site, no physical directories are used
Ah, gotcha. So essentially you need to make a rule that does exactly what mod_dir does, only with nonexistent directories. Here it's a big help if none of your directory names contain literal periods. Can I assume you are not apache dot org, whose site is littered with /2.4/ and the like? If you have no literal periods to worry about, then capturing extensionless URLs is a snap because the body of your rule need only say
meaning "no periods anywhere, and the final character is also not allowed to be a directory slash". If you don't currently use extensionless URLs for pages, then a request in this form can only be for a directory. And if you DO use extensionless page URLs, it's a non-problem because you'll be dumping the whole thing on your php anyway ;)
RewriteRule (tiny|little|big|massive)redwidgets/(.*) http://www.example.com/allredwidgets/$1 [R=301,L]
This ought to work. If you don't use an opening anchor, then it doesn't even matter if you are in htaccess (no leading slash) or config (leading slash).
But wait! I've been assuming that these are top-level requests. If there is other stuff before my-new-improved-widgets-page.html, then you have to capture that too. Since you're working with pages that formerly existed, you should be able to give the literal text. The more tightly you constrain your rule, the faster mod_rewrite can be outta there. May not matter right now, but it will make a big difference when you start getting a million daily visitors and your server is creaking at the joints :)
So, for example-- assuming htaccess--
RewriteRule ^directory/fat(red|blue|green)widgets/(.*) http://www.example.com/directory/allfatwidgets/$1[R=301,L]
Note that if we're dealing with material that comes before the part you're changing, there's no significant difference between mod_rewrite and mod_alias. But since you talk about nonexistent directories I have to assume you've already got mod_rewrite doing some things. That means you need to ditch any rules that currently use mod_alias (Redirect or RedirectMatch by that name) and convert them to mod_rewrite.
Any rule that creates a redirect goes before the rules that create rewrites alone. If it isn't your own server, the only way you can be sure this happens is by doing everything in the same module.
[edit reason] point of order [/edit]
[edited by: phranque at 12:57 am (utc) on Apr 21, 2013]