Forum Moderators: phranque
What I want to do is have each of my domains' root directories actually live in a subdirectory of the site. In other words, when someone requests www.domain1.com, they should actually be retrieving files from www.domain1.com/domain1/, but I don't want them to KNOW this. Is that possible?
I want the user to see www.domain1.com, but every request to be transparently sent to www.domain1.com/domain1/, so that if they ask for www.domain1.com/foo.gif, Apache sends them www.domain1.com/domain1/foo.gif, and they don't know this is happening.
I have this, so far (one of numerous permutations I've tried):
RewriteCond %{HTTP_HOST} .*domain1.*
RewriteRule ^(/.*)?$ /domain1$1 [L]
There are two problems here. First, users see /domain1/ appended to their address bar. Second, if they request /foo.gif, they are sent to /foo.gif and the file doesn't exist (instead of being sent to /domain1/foo.gif, which at least would work).
Suggestions?
Welcome to WebmasterWorld!
The main problem is that in .htaccess context, the leading slash is stripped off the local URL-path variable "seen" by RewriteRule.
Also, there is the possibility that your code may be looping, so I'd suggest the following changes:
RewriteCond %{HTTP_HOST} ^(www\.)?domain1
RewriteCond %{REQUEST_URI} !^/domain1
RewriteRule (.*) /domain1/$1 [L]
Jim
I have tried what you suggested, but I still have the same two problems.
1. Visitors see /domain1/ added to the URL in their address bar (this was the major one that I wasn't sure was possible to avoid), and
2. A request for www.domain1.com/foo.gif fails to redirect to /domain1/foo.gif, and so I get a 404.
I have seen mod_rewrite used in the past to take a nested directory request (for example) and instead send the user the output of a script. Such as:
www.domain1.com/images/1045/
Internally, mod_rewrite changes that to:
www.domain1.com/view_image.php?image=1045
But the user only sees the first URL in their address bar, and in fact, the "images" directory isn't a real directory. That is what I want; I don't want the user to know that the files reside in a subdirectory on the server. Is that possible in this context?
Thanks for all your help.
Your code, and the modified version I posted do not invoke an external redirect. In addition, the code should rewrite a request for *any* resource in the "domain1" subdomain to the corresponding resource located in the associated /domain1 subdirectory. So there's no reason your image file should be 404.
This code is extremely simple, so if you're seeing the browser address bar update with the code I posted, you can be sure that there's some other agency involved.
Jim