Rowan,
It’s not SitePoint’s protocol … it’s mine! There are many members (and staff) who share code. As a former instructor pilot, I’d rather see someone learn as it’s similar to the old “give a man a fish and you feed him for one day; teach him to fish and you feed him for a lifetime” so I rarely provide code without seeing at least an attempt to learn and code.
What’s your question about the RewriteRule? Simply put, it’s
RewriteRule {regex} {redirection} [{flags}]
regex: It’s PERL regex which is greatly simplified because the variables are limited to single lines of text. Moreover, each variable is strictly structured (as text or URI or …).
redirection: either an internal redirection (IN THE WEBSPACE - I think your /home/ is NOT in the webspace so that’s likely the cause of your problem) or external redirection (http://www.yadda.yadda/path/file).
flags: the modifiers dependent upon the directive.
Answers:
- Yes, but it must be relative to the DocumentRoot.
- Relative to the directory in which the .htaccess (mod_rewrite directive) resides
- You’ve got the idea: It’s relative to the CURRENT LOCATION which, for simplicity, should be your DocumentRoot. If the redirection is index.php and mod_rewrite is in your DocumentRoot, it’ll serve the /home/myaccount/public_html/index.php file. The point of not using /index.php is that the server is supposed to look at your root directory FIRST so, if there is an index.php there, that is the one that will be selected, not %{DOCUMENT_ROOT}/index.php! IMHO, that should NOT be permitted so mod_rewrite should throw an error - but I’ve got to check on that!
- I got ahead of myself with that explanation
RewriteBase was designed to UNDO a mod_alias Redirect. In other words, if you don’t have a Redirect going on, DON’T use RewriteBase! Besides, I see RewriteBase / all the time (in the DocumentRoot)! It does precisely NOTHING (but waste server cycles).
Direct outside the webspace? That’s a breach of security! So, that answer is an obvious NO! You can, however, include(); PHP scripts which are outside your webspace but you cannot link to them as they are NOT accessible via http.
Please use [ code ] … [ /code ] for your code:
RewriteEngine [COLOR="Blue"]o[/COLOR]n
[COLOR="Red"]RewriteBase /[/COLOR]
RewriteCond %{HTTP_HOST} mydomain1\\.com$ [NC]
# GOOD! This is far better than ^(www\\.)?mydomain1\\.com$
RewriteRule ^[COLOR="Red"](.*)[/COLOR]$ [COLOR="Red"]/home/myaccount/[/COLOR]dom1/$1 [QSA,NE,L]
Because you’re using “Lazy Regex,” this will LOOP adding new dom1 directories until Apache discovers that you’ve caused it to loop. Be glad that you’re not using Apache 1.x 'cause you’d have to restart to break the loop! Add another exclusion (via RewriteCond) to prevent a redirection if dom1 subdirectory is present in the {REQUEST_URI} - then LEARN regex so you’ll know why you won’t just indiscriminately use (.*) when you want to match something.
Okay, enough bashing you as you ARE trying. Unfortunately, you did manage to generate many of the errors most other ‘noobies’ manage to generate, too. My “technique” (such as it is) is to make you THINK about the code so you’ll understand what the code is doing for you and why (IMHO, (.*) is NOT a sign of a thinker UNLESS it comes with enough “exclusions” to absolutely prevent looping) it works (or doesn’t work).
PLEASE ask questions on anything you don’t understand! mod_rewrite is a VERY powerful tool and, once the few basics are learned, you’ll be teaching others to “share the wealth” that your understanding will bring to your websites.
Regards,
DK