Gilbert Nolander:
I understand what you mean when you say "To me this sentence could be in another language." I run in to that a lot and I've been working with computers for thirty-five years. Every time I try to understand a new technology or even have a discussion about existing technology, it's like learning a new language.
To answer some of your questions:
The Apache web server allows you to modify its behavior by adding modules to it. You can think of a module kind of like a Plug-In or an external library. It is just a complete (black box) entity that you can add to Apache to modify or add to it's core behavior. BTW you don't have add the module to Apache, your web host will do that or not as they see fit. If they have already added the mod_rewrite module, then you can create a .htaccess file to modify the standard behavior of Apache.
Rule based means that you provide rules in your .htaccess file that tell the mod_rewrite module how to behave. Each rule starts with a rule name such as RewriteEngine, RewriteCond, RewriteRule, RewriteMatch, etc. You can then provide values to tell mod_rewrite what to do. For example, you need a rule that says 'RewriteEngine On' to ensure that mod_rewrite will use your redirect commands.
The part of mod_rewrite that reads and executes your .htaccess file is called the RewriteEngine. This is really just another term to refer to mod_rewrite.
A regular expression is a way to specify a pattern. It is used to look for patterns in strings. For example, if I have a file that has the name 'Gilbert' in it somewhere, I can run a program that interprets regular expressions and tell it to print each line that contains the pattern 'Gilbert'.
The pattern Gilbert is the simplest kind of regular expression because each character in the pattern matches exactly that pattern in the searched file.
Regular expressions are very powerful and can be used to find many different kinds of patterns, For example, I can find all words that start with an uppercase letter followed by one or more lowercase letters with the pattern '[A-Z][a-z]+'. You shouldn't need any patterns more complicated than that.
I think that IIS also allows you to use a .htaccess file, but you would need to check on that if you are on an IIS server.
I think the following would allow you to do what you want. Just put it into a file called .htaccess, upload the .htaccess file to the root directory of your web pages and test it. It should go in the same directory with the index.html file that you see when you type http://www.jeff-nolan.com/index.html in the address bar of your browser.
code:
RewriteEngine On
RewriteCond %{HTTP_HOST} (ww+\.)?woolenwhimsy.com
RewriteCond %{REQUEST_URI} !/woolenwhimsy/
RewriteRule (.*) /woolenwhimsy/$1
Make sure to upload this as a plain ASCII file. Tell your FTP program that the file is ASCII so it will translate the end of line characters as it transfers the file.
The line 'RewriteEngine On' makes sure that mod_rewrite is processing your URIs.
'RewriteCond %{HTTP_HOST} (ww+\.)?.woolenwhimsy.com' says to only process the following lines when the HOST part of the URI contains 'woolenwhimsy.com', with or without a leading 'www.'. Note: the part of the line after %{HTTP_HOST} is a regular expression. 'ww+' looks for two or more 'w's in a row follows by a '.'. The '?' says that the entire expression in parentheses is optional.
'RewriteCond %{REQUEST_URI} !/woolenwhimsy/' says to not process the line if it already contains the directory /woolenwhimsy/, This is a simple regular expression with a 'not' (!) symbol in front of it. If it matches the string '/woolenwhimsy/' it fails.
'RewriteRule (.*) /woolenwhimsy/$1' says to process any line that matches the above conditions by prepending '/woolenwhimsy/' to whatever the line already contains. Note: (.*) is another regular expression with matches all characters in the line. The RewriteRule only matches the REQUEST_URI part of the URI and will automatically prepend the HTTP_HOST to the resulting URI (unless you specify an external reference, which we won't get into here).
For example, If you enter 'http://www.woolenwhimsy.com/page1.html' in the address bar of your web browser, when the request gets to your host machine, the web server will pass the URI to mod_rewrite. mod_rewrite will compare the URI to the first RewriteCond. The URI matches because it does contain 'www.woolenwhimsey.com' in the %{HTTP_HOST} part of the URI.
It then checks to see if the %{REQUEST_URI} contains the directory name '/woolenwhimsy/'. Since it does not, the URI passes this test.
Now mod_rewrite executes the RewriteCond statement. It matches every thing in the %{REQUEST_URI}, i.e, 'page1.html', and appends it to '/woolenwhimsy/'. This gives you a URI of 'http://www.woolenwhimsey.com/woolenwhimsey/page1.html'.
Since this is the last line in .htaccess, the rewrite engine now passes this new URI back to the start of processing and runs the URI through the same process again.
It checks the %{HTTP_HOST} to see if it contains www.woolenwhimsey.com. It does so it checks to see if the %{REQUEST_URI} contains /woolenwhimsy/. Since it does, this RewriteCond fails and the URI is passed, as is, back to the server which completes the request.
If you have a file called 'page1.html' in the directory '/woolenwhimsy/' on your server, the server will pass it back to the client machine. Otherwise, it will generate a 404 message.
Since this is a local redirect, the content of the address bar on your browser should not change. If it had been an external redirect, the server would have notified the browser and it would have changed the address bar.
I hope that helps. Try out this file and let us know if it works. Also if you find this confusing or unclear, please ask more questions.
.
-- not necessarily stoned... just beautiful.