Struggling trying to find out if this is even possible. I have a folder that contains a 'mini site' on a website (actually 38 of them), these mini site folders are located in a folder called 'sites'. We did this because when the site was bought these folders were all over the root (along with a thousand other nonsense files) and we needed to organize it some.

Well the owner doesn't like the {domain}/sites/mini-site-folder/ layout and wants them to be {domain}/mini-sites-folder

Now short of moving them all back to the root folder I can't seem to find a way to alias them so that {domain}/mini-sites-folder resolves to {domain}/sites/mini-site-folder/ I asked my server guy to look at it and he tried for a few days but couldn't come up with anything.

I'm pretty sure there is a way to do it because I've seen things like this done on other sites but for the life of me (and my server guy) I can't find it

Any help would be appreciated .... I shudder at the thought of moving them all back into the root

Do you have access to httpd.conf (actually, the httpd-vhosts.conf for your domain)? If so, move all the Redirects that work there so they're only read once (rather than for EVERY @#$% file request!).

Yes once we get all the issues solved it will all get neatly packed in the config file.

dklynn said:

How is RedirectMatch 301 /hollis /hollis-farms/ supposed to tell hollis{followed by anything} from hollis-farms? Admittedly, I see your mod_alias directive with my mod_rewrite (regex) blinders on but it looks like it should be loopy!

:tup: "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

That's what I'd expect.

So basically you are saying those couple are no gos?

dklynn said:

Since you have that for (all?) your RedirectMatch statements, I'm shocked that your Apache hasn't packed up its teepee and headed for the Great Plains!

Note that BOTH red bits WILL match rrreoirthwerhiew with the sites/rrreoirthwerhiew taking precedence (order) at which time `RewriteCond %{REQUEST_URI} !\.(js|jpe?g|gif|css|swf|html|jsp|ico|png|xml|xsl|rdf|txt|gz|php|pdf|zip|htm)$ [NC]

RewriteRule ^([^/]+)/([^/]+)$ index.php?pageName=$1&id=$2 [L]` will kick-in and redirect to index.php with sites as the pageName value and id=rrreoirthwerhiew! If index.php can't handle that jibberish, you're in real trouble!

Does that mean you've fixed it the way you need?

I have fixed the internal server error problems by moving your code below mine, my PHP handler grabs it and shows on of my error pages

dklynn said:

IMHO, you need to "trim" your .htaccess to something more reasonable else you'll be burdening your server far too much with every file request.

Yes we know it is huge and burdensome but it will be moved to the config file once testing is done ... the problem here is we are trying to 'fix' a site that has been an utter disaster since it was created in 1996, this guy just piled more and more crap on in any way shape or form he could .... now the real problem is the site has some amazing rankings (why it was bought by my client)

dklynn said:

Then think like mod_rewrite and "see" how each request is handled - remembering to follow the redirections through the next loop (mod_rewrite keeps looping back through until no more redirections are found/executed).

What you've encountered is similar to the problem that noobies have when they use (.*) to match (NOTHING or EVERYTHING) and wonder why their redirections never end (go loopy). If you're as exact as possible in defining the {REQUEST_URI} string which you need to be redirected, that tends to avoid the loop problem.

Do you have access to httpd.conf (actually, the httpd-vhosts.conf for your domain)? If so, move all the Redirects that work there so they're only read once (rather than for EVERY @#$% file request!).

How is RedirectMatch 301 /hollis /hollis-farms/ supposed to tell hollis{followed by anything} from hollis-farms? Admittedly, I see your mod_alias directive with my mod_rewrite (regex) blinders on but it looks like it should be loopy!

:tup: "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

That's what I'd expect.

Since you have that for (all?) your RedirectMatch statements, I'm shocked that your Apache hasn't packed up its teepee and headed for the Great Plains!

It dawned on me after testing that the old folder (hollis) is the first word in the new folder and every one that is like that throws the same error. The ones (like the working one above) had a goofy folder name like pipecreek or dht, or hht) .... that first word in the new folder name no longer exists so the new rewrite condition and rule you posted works as expected.

will kick-in and redirect to index.php with sites as the pageName value and id=rrreoirthwerhiew! If index.php can't handle that jibberish, you're in real trouble!

dc_dalton said:

I was able to solve the internal server error when nothing was found (my gibberish url above) and the problem of my rewrite not working for the site pages by moving your condition after mine .... making progress here.

Does that mean you've fixed it the way you need?

IMHO, you need to "trim" your .htaccess to something more reasonable else you'll be burdening your server far too much with every file request.

Then think like mod_rewrite and "see" how each request is handled - remembering to follow the redirections through the next loop (mod_rewrite keeps looping back through until no more redirections are found/executed).

What you've encountered is similar to the problem that noobies have when they use (.*) to match (NOTHING or EVERYTHING) and wonder why their redirections never end (go loopy). If you're as exact as possible in defining the {REQUEST_URI} string which you need to be redirected, that tends to avoid the loop problem.

I was able to solve the internal server error when nothing was found (my gibberish url above) and the problem of my rewrite not working for the site pages by moving your condition after mine .... making progress here.

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

It dawned on me after testing that the old folder (hollis) is the first word in the new folder and every one that is like that throws the same error. The ones (like the working one above) had a goofy folder name like pipecreek or dht, or hht) .... that first word in the new folder name no longer exists so the new rewrite condition and rule you posted works as expected.

When nothing is found (for example adding gibberish to the url) example:

I get an internal server error. This bothers me because there are many pages that no longer exist and we want a 404 to be thrown. Is there a 'graceful' way to send them to a 404 page that can be added to your code?

And just so you are getting the entire picture here is the complete htaccess file:

Crap, just noticed another error that's happening ..... my rewrite (for the site pages) is throwing an internal server error for everything. It seems to work if I move your code after mine but will have to do more testing to make sure.

:tup: Test using .htaccess then update the server's configuration files. You KNOW what you're doing! :tup:

Right! The "loopy" Redirects can (WILL) cause problems. Note, though, when you change subdirectory names, there is no problem. IMHO, though, you shouldn't need both the / and non-/ version of the directories as Apache will understand (and add the / if you're specifying a directory) so the / version should cover both.

Moving mod_rewrite code WILL (as shown above) alter the order of the processing and affect the ultimate redirection. Do the "mod_rewrite walkthrough" with valid and invalid URLs to check what the results should be (then verify with R=301 redirects if you need to confirm your judgment).

Of course, because you have access to the httpd.conf, you also have access to using RewriteMap. I'd setup a RewriteMap for a client to do something much like what you're doing by creating a script to access a database table for the redirects (for hundreds of pages). If you can "hardwire" using Redirects or RewriteRules in httpd.conf, it'll be faster but, if that's too much of a PITA, have a look at RewriteMaps, too, specifically the External Rewriting Program section.

mod_alias will do that for you as well as mod_rewrite. If it weren't for the obvious misdirections that would occur with mod_alias (unless there are no "normal," i.e., non mini-site subdirectories), your best bet would be to use mod_rewrite to CHECK whether the {REQUEST_FILENAME} exists as a file or directory then (if NOT) internally redirect to the sites subdirectory with the {REQUEST_URI}.

mod_alias will do that for you as well as mod_rewrite. If it weren't for the obvious misdirections that would occur with mod_alias (unless there are no "normal," i.e., non mini-site subdirectories), your best bet would be to use mod_rewrite to CHECK whether the {REQUEST_FILENAME} exists as a file or directory then (if NOT) internally redirect to the sites subdirectory with the {REQUEST_URI}.