http:// shows protocol and it exists in any URL you open in browser actually
Modern browsers just hide it in address bar, but if you copy and paste URL from browser’s address bar to notepad you’ll see protocol is still there.
Here you can learn how to force redirect to WWW subdomain.
If you set a domain level cookie then it will be accessible to all sub domains within mysite.com so the presence or not of the www would then not make any difference.
What have you got against trailing slashes (on the domain or subdirectory)? They only make life easier for Apache.
Actually, the code given specified the trailing slash on the domain. You MIGHT be able to avoid that by using Apache’s {REQUEST_URI} variable as it actually contains the slash between the domain and URI (in Apache 2.x, it’s hidden by default but used in redirections).
The link showed the preferred way to make SIMPLE redirects using mod_alias. mod_alias is much faster because it doesn’t load the regex engine but it’s not able to pattern match nor access other server variables the way mod_rewrite does. For this redirection (forcing the www. in the domain), mod_alias is the hammer while mod_rewrite is the sledge hammer, i.e., not the proper tool.
If you have other (more complex) redirections, it probably doesn’t matter because you’ll have to load the regex engine anyway to access the power of mod_rewrite.
More information (and examples) about mod_rewrite at my tutorial at http://dk.co.nz/seo.
I just figured it looks prettier without a trailing slash, plus I think that is what most people are used to seeing. (To me, a trailing slash means “directory”.)
I also asked about what this was and how to implement it…
Using the rewrite engine is a pretty heavyweight way to solve this problem. Here is a simpler solution:
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>
And then youll have another < VirtualHost > section with ServerName www.example.com for your real server configuration. Apache automatically preserves anything after the / when using the Redirect directive, which is a common misconception about why this method wont work (when in fact it does).
DocumentRoot IS a directory, however, the code you used REQUIRED the / for a null {REQUEST_URI} so the “error” was with your redirection statement.
What I was recommending was to learn the first rule of mod_rewrite: Only use mod_rewrite when there is not a better/faster tool, in this case, mod_alias.
Your code was not really overkill but was the cause of the trailing slash on the domain only redirection. The same applies to your virtual host code (eliminate the trailing / if you don’t like to see it) from StackOverflow.
If you want example code for real world problems which are easily resolved using mod_rewrite, try http://dk.co.nz/seo rather than post links to StackOverflow which are creating the problem you’re trying to solve.
Please note that one of my pet peeves is for a “webmaster” to use code when he has no clue as to what it does - and that fits this case precisely (with regard to your use of StackOverflow code). If you have questions about my mod_rewrite tutorial or any of the code therein, you know where to find me - although the explanations that are associated with my code samples should make it very clear what they do…