views:

13

answers:

2

I've been trying to get some RewriteRules working and am successful when just using for one host, but not multiple.

I'm wanting "http://preview.domain.com" to point to "http://preview.domain.com/dir1" or "http://preview.domain.com/dir2", etc. Dir1 and Dir2 are as they contain a ProxyPass that points to the real domain. Here is what I have currently :

RewriteCond %{REQUEST_URI} !/dir1
RewriteRule ^(.*)$ /dir$1 [R]

<Location /dir1>
ProxyPass http://dir1.com
</Location>

I can't get the dir2 Rules to work beside the ones above. I am wanting to make this dynamic if possible as their are about 70 folders and growing. "http://preview.domain.com" is essentially a domain to point to my dev server to show dev content instead of prod content without having to modify the website code. Could anyone provide help?

A: 

I don't exactly understand what you're trying to do. If you want http://preview.domain.com/nameofsite/path to map to http://nameofsite.com/path (where nameofsite is a placeholder for whatever domain name you're using), you could use

RewriteRule ^/([^/]+)(/.*)$ http://$1.com$2 [P]

and then you wouldn't have any need for the Location block.

David Zaslavsky
A: 

Not sure how to do just a reply, but I just wanted to clarify the issue. Using your Rewrite give my link a 404. Not sure if I just need a proper RewriteCond or whatnot. The my first rewrite above works fine for a single site proxy, but I want to add several more and I'm not sure how the rewrite rules need to work. At first I added a second rewrite block similar to the first, just pointed to a different site and when I attempt to access it at "http://preview.domain.com/dir2", it rewrites it to "http://preview.domain.com/dir2/dir1" and fails.