Disclaimer
This information HAS errors and is made available WITHOUT ANY WARRANTY OF ANY KIND and without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is not permissible to be read by anyone who has ever met a lawyer or attorney. Use is confined to Engineers with more than 370 course hours of engineering.
If you see an error contact:
+1(785) 841 3089
inform@xtronics.com
Apache
System check - Syntax testing
$ apache2ctl configtest
- Get a list of all virtual hosts which are defined in all apache configuration files:
$ apache2ctl -S
Redirect RedirectMatch Rewrite
First the differences
- Redirect sends folks looking for one url to another - that they always see in the address-bar
- RedirectMatch Just like Redircect except you can pass parts of the old url to the new url
- Rewrite Can do all that and send a different url and not tell the browser.
The choice depends on just what you need to do. Rewrite is complex -
learning curve - but you can serve alternative urls without giving a
HTML code. If you are only doing a simple redirection - possibly
matching some urls - redirect is the way to go. When you can't do it
with Redirect, you will probably want to start learning Mod_Rewrite.
- Important - if you rewrite to the whole url ( http://example.com/fishnets.htm
) - it redirects and the address bar in the browser is updated. If
instead you rewrite without the domain parte ( /fishnets.htm ) it only
sends it - the url is unchanged unless you issue a R= flag.
Rewrite Notes
Flags
Rewrite Flags - multiple flags are separated by commas [C,B]
- L = Last. Stop processing RewriteRules once this one matches. Order counts!
- C = Chain. Continue processing the next RewriteRule. If
this rule doesn't match, then the next rule won't be executed. More on
this later.
- E = Set environmental variable. Apache has various environmental variables that can affect web-server behavior.
- F = Forbidden. Returns a 403-Forbidden error if this rule matches.
- G = Gone. Returns a 410-Gone error if this rule matches.
- H = Handler. Forces the request to be handled as if it were the specified MIME-type.
- N = Next. Forces the rule to start over again and re-match. BE CAREFUL! Loops can result.
- NC = No case. Allows [jpg] to match both jpg and JPG.
- NE = No escape. Prevents the rewriting of special characters (. ? # & etc) into their hex-code equivalents.
- NS = No subrequests. If you're using server-side-includes, this will prevent matches to the included files.
- P = Proxy. Forces the rule to be handled by mod_proxy.
Transparently provide content from other servers, because your
web-server fetches it and re-serves it. This is a dangerous flag, as a
poorly written one will turn your web-server into an open-proxy and That
is Bad.
- PT = Pass Through. Take into account Alias statements in RewriteRule matching.
- QSA = QSAppend. When the original string contains a query
(http://example.com/thing?asp=foo) append the original query string to
the rewritten string. Normally it would be discarded. Important for
dynamic content.
- R = Redirect. Provide an HTTP redirect to the specified
URL. Can also provide exact redirect code [R=303]. Very similar to
RedirectMatch, which is faster and should be used when possible.
- S = Skip. Skip this rule.
- T = Type. Specify the mime-type of the returned content. Very similar to the AddType directive.
Matching and Escaping
- Use the \ (back-slash) to escape any of the following characters. * . $ + \ become \* \. \$ \+ \[ \]
Simple matching
^ Start matching at this point
$ End point of the match
. Any character
[] Starts a class
| Starts alternative match this|that would mean match this or that
() starts a back reference point
? match 0 or 1 time Quantifier
+ match atleast 1 or more times Quantifier
* match 0 to infinite times Quantifier
{} match minimum to maximum Quantifier {0,3} match up to 3 times
Class Definitions
- What is in the brackets [] denotes a class
Char. Definition
^ Negates the class. [^A-Z]+ means don't match any uppercases
\ Use before any of the following characters to escape or null the meaning or it. [\+]+
- Range for matching [0-9]+ [a-zA-Z]+
Apache error log
Ignore these
[error] Hostname 123.123.123.123 provided via SNI and hostname example.com provided via HTTP are different
From a bot that is using the IP rather than the domain name.
[error] [client 195.159.233.44] rejecting client initiated renegotiation
Someone probing TLS
www-prefix
Using a www-prfix advertised stupidity. www is spam and not useful
Dump the www in your configs and register at
http://no-www.org/