HI Norman,
It gives me a “cheap thrill” to know that I’ve helped someone “turn the light on” so they can go off and help someone else with the same thing.
Oh, my! Apache variables are available to mod_rewrite (Apache.org has a number of them listed in their mod_rewrite documentation) but the ones you’re asking about are VERY BASIC to every URL (Uniform Resource Locator - web page address) and every webmaster should be intimately familiar with them.:
URL = Web page address, e.g., http://www.datakoncepts.com/seo.php?query=nothing+special
The protocol is the http:// which signifies that you’re asking for an Internet web page. The protocols for web pages are either http:// or https:// (secure/encrypted). The https:// protocol is denoted by %{HTTPS} and is either on or null.
The domain is datakoncepts.com; the subdomain is www and, in today’s context, www is generally not necessary (depending upon how the domain is registered on the host … in its A Record; but don’t worry about this now).
The URI (Uniform Resource Identifiers) are everything after the domain name up to but NOT including ? or # (reserved characters). Above, it’s seo.php
The query string follows the “marker” (? merely separates the URI and the query string). The query string is normally made up of key=value pairs (separated by &'s). If the value string contains spaces, they’ve been replaced by +'s (because spaces are reserved characters and not allowed in a URL).
The other separator “marker” is the # which denotes that the following characters provide the name of an “anchor” in the URI’s page (so long pages like my seo can redirect to a specific location in the page rather than scroll endlessly looking for the appropriate location).
In short: {protocol}{domain}/{URI}?{query string}#{anchor}
or, using Apache variables (they’re normally denoted with a preceding % to let Apache know to look at its variables):
http:// %{HTTP_HOST} %{REQUEST_URI} ? %{QUERY_STRING}
http:// datakoncepts.com /seo.php ? query=nothing+special
I do not believe the page anchor is available to mod_rewrite but can check on that if you like.
It’s far easier to provide for exclusions in your redirections (the X, Y and Z) when creating the redirection rather than when going back and modifying. To provide an example, let me assume that your pages are all .html pages and X is contact.html, Y is about.html and Z is location.html. Okay, it’s JUST an example for you to consider!
[code]RewriteEngine on
# Makes sure that mod_rewrite is NOT in "Comment Mode"
#
RewriteCond %{HTTP_HOST} old\.domain$ [NC]
# ONLY necessary if old.domain and new.domain are sharing the same space on your server
# Where old.domain is like my datakoncepts.com
# The \ is so that the . (dot) character will only match the dot character not one of ANY character
# The No Case flag ( [NC] ) is required because the {HTTP_HOST} is NOT case sensitive
#
RewriteRule !^[contact|about|location|index]\.html$ /index.html?request=%{REQUEST_URI} [R=301,L]
# To redirect all pages EXCEPT contact.html, about.html, location.html and avoid looping on index.html
# Escape the dot character in the regex so it will only match the dot character
# Redirect by sending EVERYTHING ELSE to index.html
# Optionally add a query string denoting the request using the requested URI as its value
#
# OR
#
RewriteRule !^[contact|about|location]\.html$ http://new.domain/ [R=301,L]
# Do ***NOT*** use both RewriteRules as only one should apply
# - the first will take precedence
# Comment out or delete the one you do not want to use![/code]
If X, Y and Z had not been specified, they would have received PERMANENT redirections to new.domain (too late to retain at old.domain).
There’s a lot to learn about mod_rewrite but it is an exceptional tool in the hands of a knowledgeable webmaster. Take the time to learn (sufficient motivation should be provided in checking out the examples on the tutorial page).
Regards,
DK