Forum Moderators: phranque
RewriteCond %{HTTP_HOST} testing.mydomain.com
RewriteCond %{REQUEST_URI}!testing/
RewriteRule ^(.*)$ testing/$1 [L]
That works beautifully. I'm using the /testing directory, and the testing.mydomain.com subdomain as a testing area where I can build/test on my website without danger of messing up the "live" website.
Problem is, though, that when I browse to testing.mydomain.com/subdir1, I really get the contents of www.mydomain.com/subdir1.
As an example, I need to be able to access the text file /testing/subdir1/textfile.txt as testing.mydomain.com/subdir1/textfile.txt. Presently, testing.mydomain.com/subdir1/textfile.txt will return a 404 since the file does not exist in /subdir1 , only in /testing/subdir1/ .
I've looked at Apache's docs on mod_rewrite and .htaccess, but am not sure how to proceed.
Any suggestions?
First, make sure you disable MultiViews unless you are using them.
Second, try enabling RewriteOptions Inherit in /testing/subdir -- Inherit may not be set in your default server config.
I'd also suggest some cleanups/speedups on your code:
RewriteCond %{HTTP_HOST} ^testing\.mydomain\.com
RewriteCond %{REQUEST_URI} !^/testing/
RewriteRule (.*) /testing/$1 [L]
Maybe I'm not clear on what you expected or want to happen.
After resolving to your IP address and being processed through http.conf, the "subdomain name" pretty much loses its meaning. Inside the server, there are no domains, subdomains or URLs -- there are only directories, subdirectories, and files. In either httpd.conf or in .htaccess, the entire URL is translated into a file system path. So, your "domain name" is discarded having reached the server, the subdomain becomes a subdirectory (in typical configurations), and is therfore accessible via any URL that will navigate into your server's Web-acessible filesystem.
If you want to prevent "direct access" via www.mydomain.com/subdir1, then use RewriteCond %{THE_REQUEST} to test that the browser-requested URL is *not* www.mydomain.com/subdir1. Other code, depending on %{REQUEST_URI} and the URI seen by RewriteRule, will not examine the requested URI, but rather the rewritten URI (if any rewriting has already occurred). However, %{THE_REQUEST} is not affected by rewriting -- it always contains the request sent by the browser.
See this related recent thread [webmasterworld.com].
Jim
www.mydomain.com/abc/file.txt should retrieve /homedir/user/www/abc/file.txt.
testing.mydomain.com/abc/file.txt should retrieve /homedir/user/www/testing/abc/file.txt.
I know that this is possible - - this is what setting up a "subdomain" in cPanel does. cPanel does not use .htaccess to accomplish this, as I never saw any changes to my .htaccess files when I was hosting with a cPanel host.
My current host does not use cPanel, and I'm trying to figure out if this is possible to accomplish with .htaccess. Yes, I can pay them to do it for me, but I'd *really* like to know how to do this myself.
Perhaps this is not possible with .htaccess.
Thank you for your assistance.
-jared
RewriteCond $1 !^(devŠtest)/
RewriteCond %{HTTP_HOST} ^(devŠtest)\.example\.org
RewriteRule ^(.*) /%1/$1 [L]
Replace the broken pipe "Š" characters above with solid pipes before attemptiing to use this code.
Jim
[edited by: jdMorgan at 8:16 pm (utc) on Feb. 23, 2005]