| /30 - 64 Subnets 2 Hosts/Subnet |
/29 - 32 Subnets 6 Hosts/Subnet |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
| /28 - 16 Subnets 14 Hosts/Subnet |
/27 - 8 Subnets 30 Hosts/Subnet |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
| /26 - 4 Subnets 62 Hosts/Subnet |
/25 - 2 Subnets 126 Hosts/Subnet |
||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
| /24 - 1 Subnets 254 Hosts/Subnet |
|||||||
|---|---|---|---|---|---|---|---|
|
| Small to Large Subnets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
For subnetting and general IP tools check here IPThingy.com
Modes
Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for “colon” commands which execute when you press the return key.
Quiting
:x Exit, saving changes
:q Exit as long as there have been no changes
ZZ Exit and save changes if any have been made
:q! Exit and ignore any changes
Inserting Text
i Insert before cursor
I Insert before line
a Append after cursor
A Append after line
o Open a new line after current line
O Open a new line before current line
r Replace one character
R Replace many characters
Motion
h Move left
j Move down
k Move up
l Move right
w Move to next word
W Move to next blank delimited word
b Move to the beginning of the word
B Move to the beginning of blank delimted word
e Move to the end of the word
E Move to the end of Blank delimited word
( Move a sentance back
) Move a sentance forward
{ Move a paragraph back
} Move a paragraph forward
0 Move to the begining of the line
$ Move to the end of the line
1G Move to the first line of the file
G Move to the last line of the file
nG Move to nth line of the file
:n Move to nth line of the file
fc Move forward to c
Fc Move back to c
H Move to top of screen
M Move to middle of screen
L Move to botton of screen
% Move to associated ( ), { }, [ ]
Deleting Text
Almost all deletion commands are performed by typing d followed by a motion. For example, dw deletes a word. A few other deletes are:
x Delete character to the right of cursor
X Delete character to the left of cursor
D Delete to the end of the line
dd Delete current line
:d Delete current line
Yanking Text
Like deletion, almost all yank commands are performed by typing y followed by a motion. For example, y$ yanks to the end of the line. Two other yank commands are:
yy Yank the current line
:y Yank the current line
Changing text
The change command is a deletion command that leaves the editor in insert mode. It is performed by typing c followed by a motion. For wxample cw changes a word. A few other change commands are:
C Change to the end of the line
cc Change the whole line
Putting text
p Put after the position or after the line
P Put before the poition or before the line
Buffers
Named buffers may be specified before any deletion, change, yank or put command. The general prefix has the form “c where c is any lowercase character. for example, “adw deletes a word into buffer a. It may thereafter be put back into text with an appropriate “ap.
Markers
Named markers may be set on any line in a file. Any lower case letter may be a marker name. Markers may also be used as limits for ranges.
mc Set marker c on this line
`c Go to beginning of marker c line.
‘c Go to first non-blank character of marker c line.
Search for strings
/string Search forward for string
?string Search back for string
n Search for next instance of string
N Search for previous instance of string
Replace
The search and replace function is accomplished with the :s command. It is commonly used in combination with ranges or the :g command (below).
:s/pattern/string/flags Replace pattern with string according to flags.
g Flag - Replace all occurences of pattern
c Flag - Confirm replaces.
& Repeat last :s command
Regular Expressions
. (dot) Any single character except newline
* zero or more occurances of any character
[...] Any single character specified in the set
[^...] Any single character not specified in the set
^ Anchor - beginning of the line
$ Anchor - end of line
\< Anchor - begining of word
\> Anchor - end of word
\(…\) Grouping - usually used to group conditions
\n Contents of nth grouping
[...] - Set Examples [A-Z] The SET from Capital A to Capital Z
[a-z] The SET from lowercase a to lowercase z
[0-9] The SET from 0 to 9 (All numerals)
[./=+] The SET containing . (dot), / (slash), =, and +
[-A-F] The SET from Capital A to Capital F and the dash (dashes must be specified first)
[0-9 A-Z] The SET containing all capital letters and digits and a space
[A-Z][a-zA-Z] In the first position, the SET from Capital A to Capital Z
In the second character position, the SET containing all letters
Regular Expression Examples /Hello/ Matches if the line contains the value Hello
/^TEST$/ Matches if the line contains TEST by itself
/^[a-zA-Z]/ Matches if the line starts with any letter
/^[a-z].*/ Matches if the first character of the line is a-z and there is at least one more of any character following it
/2134$/ Matches if line ends with 2134
/\(21|35\)/ Matches is the line contains 21 or 35
Note the use of ( ) with the pipe symbol to specify the ‘or’ condition
/[0-9]*/ Matches if there are zero or more numbers in the line
/^[^#]/ Matches if the first character is not a # in the line
Notes:
1. Regular expressions are case sensitive
2. Regular expressions are to be used where pattern is specified
Counts
Nearly every command may be preceded by a number that specifies how many times it is to be performed. For example, 5dw will delete 5 words and 3fe will move the cursor forward to the 3rd occurence of the letter e. Even insertions may be repeated conveniently with thismethod, say to insert the same line 100 times.
Ranges
Ranges may precede most “colon” commands and cause them to be executed on a line or lines. For example :3,7d would delete lines 3-7. Ranges are commonly combined with the :s command to perform a replacement on several lines, as with :.,$s/pattern/string/g to make a replacement from the current line to the end of the file.
:n,m Range - Lines n-m
:. Range - Current line
:$ Range - Last line
:’c Range - Marker c
:% Range - All lines in file
:g/pattern/ Range - All lines that contain pattern
Files
:w file Write to file
:r file Read file in after line
:n Go to next file
:p Go to previos file
:e file Edit file
!!program Replace line with output from program
Other
~ Toggle upp and lower case
J Join lines
. Repeat last text-changing command
u Undo last change
U Undo all changes to line
CONTEXTS SIGILS ARRAYS HASHES
void $scalar whole: @array %hash
scalar @array slice: @array[0, 2] @hash{'a', 'b'}
list %hash element: $array[0] $hash{'a'}
&sub
*glob SCALAR VALUES
number, string, reference, glob, undef
REFERENCES
\ references $$foo[1] aka $foo->[1]
$@%&* dereference $$foo{bar} aka $foo->{bar}
[] anon. arrayref ${$$foo[1]}[2] aka $foo->[1]->[2]
{} anon. hashref ${$$foo[1]}[2] aka $foo->[1][2]
\() list of refs
NUMBERS vs STRINGS LINKS
OPERATOR PRECEDENCE = = perl.plover.com
-> + . search.cpan.org
++ -- == != eq ne cpan.org
** < > <= >= lt gt le ge pm.org
! ~ \ u+ u- <=> cmp tpj.com
=~ !~ perldoc.com
* / % x SYNTAX
+ - . for (LIST) { }, for (a;b;c) { }
<< >> while ( ) { }, until ( ) { }
named uops if ( ) { } elsif ( ) { } else { }
< > <= >= lt gt le ge unless ( ) { } elsif ( ) { } else { }
== != <=> eq ne cmp for equals foreach (ALWAYS)
&
| ^ REGEX METACHARS REGEX MODIFIERS
&& ^ string begin /i case insens.
|| $ str. end (before \n) /m line based ^$
.. ... + one or more /s . includes \n
?: * zero or more /x ign. wh.space
= += -= *= etc. ? zero or one /g global
, => {3,7} repeat in range
list ops () capture REGEX CHARCLASSES
not (?:) no capture . == [^\n]
and [] character class \s == [\x20\f\t\r\n]
or xor | alternation \w == [A-Za-z0-9_]
\b word boundary \d == [0-9]
\z string end \S, \W and \D negate
DO
use strict; DON'T LINKS
use warnings; "$foo" perl.com
my $var; $$variable_name perlmonks.org
open() or die $!; `$userinput` use.perl.org
use Modules; /$userinput/ perl.apache.org
parrotcode.org
FUNCTION RETURN LISTS
stat localtime caller SPECIAL VARIABLES
0 dev 0 second 0 package $_ default variable
1 ino 1 minute 1 filename $0 program name
2 mode 2 hour 2 line $/ input separator
3 nlink 3 day 3 subroutine $\ output separator
4 uid 4 month-1 4 hasargs $| autoflush
5 gid 5 year-1900 5 wantarray $! sys/libcall error
6 rdev 6 weekday 6 evaltext $@ eval error
7 size 7 yearday 7 is_require $$ process ID
8 atime 8 is_dst 8 hints $. line number
9 mtime 9 bitmask @ARGV command line args
10 ctime just use @INC include paths
11 blksz POSIX:: 3..9 only @_ subroutine args
12 blcks strftime! with EXPR %ENV environment
Syntax
selector {property: value;}
External Style Sheet
<link rel=”stylesheet” type=”text/css” href=”style.css” />
Internal Style
<style type=”text/css”>
selector {property: value;}
</style>
Inline Style
<tag style=”property: value”>
General
Class String preceded by a period
ID String preceded by a hash mark
div Formats structure or block of text
span Inline formatting
color Foreground color
cursor Appearance of the cursor
display
block; inline; list-item; none
overflow How content overflowing its box is handled
visible, hidden, scroll, auto
visibility
visible, hidden
Fonts
font-style
Italic, normal
font-variant
normal, small-caps
font-weight
bold, normal, lighter, bolder, integer (100-900)
font-size Size of the font
font-family Specific font(s) to be used
Text
letter-spacing Space between letters
line-height Vertical distance between baselines
text-align Horizontal alignment
text-decoration
blink, line-through, none, overline, underline
text-indent First line indentation
text-transform
capitalize, lowercase, uppercase
vertical-align Vertical alignment
word-spacing Spacing between words
CSS Box
height; width; margin-top; margin-right; margin-bottom; margin-left; padding-top; padding-right; padding-bottom; padding-left;
Border
border-width Width of the border
border-style
dashed; dotted; double; groove; inset; outset; ridge; solid; none
border-color Color of the border
Position
clear Any floating elements around the element?
both, left, right, none
float Floats to a specified side
left, right, none
left The left position of an element
auto, length values (pt, in, cm, px)
top The top position of an element
auto, length values (pt, in, cm, px)
position
static, relative, absolute
z-index Element above or below overlapping elements?
auto, integer (higher numbers on top)
Background
background-color Background color
background-image Background image
background-repeat
repeat, no-repeat, repeat-x, repeat-y
background-attachment Background image scroll with the element?
scroll, fixed
background-position
(x y), top, center, bottom, left, right
List
list-style-type Type of bullet or numbering in the list
disc; circle; square; decimal; lower-roman; upper-roman; lower-alpha; upper-alpha; none
list-style-position Position of the bullet or number in a list
inside; outside
list-style-image Image to be used as the bullet in a list
Selecting a database
mysql> USE database;
Listing databases
mysql> SHOW DATABASES;
Listing tables in a db
mysql> SHOW TABLES;
Describing the format of a table
mysql> DESCRIBE table;
Creating a database
mysql> CREATE DATABASE db_name;
Creating a table
mysql> CREATE TABLE table_name (field1_name TYPE(SIZE), field2_name TYPE(SIZE));
Ex: mysql> CREATE TABLE pet (name VARCHAR(20), sex CHAR(1), birth DATE);
Load tab-delimited data into a table
mysql> LOAD DATA LOCAL INFILE “infile.txt” INTO TABLE table_name;
(Use \n for NULL)
Inserting one row at a time
mysql> INSERT INTO table_name VALUES (’MyName’, ‘MyOwner’, ‘2002-08-31?);
(Use NULL for NULL)
Retrieving information (general)
mysql> SELECT from_columns FROM table WHERE conditions;
All values: SELECT * FROM table;
Some values: SELECT * FROM table WHERE rec_name = “value”;
Multiple critera: SELECT * FROM TABLE WHERE rec1 = “value1? AND rec2 = “value2?;
Reloading a new data set into existing table
mysql> SET AUTOCOMMIT=1; # used for quick recreation of table
mysql> DELETE FROM pet;
mysql> LOAD DATA LOCAL INFILE “infile.txt” INTO TABLE table;
Fixing all records with a certain value
mysql> UPDATE table SET column_name = “new_value” WHERE record_name = “value”;
Selecting specific columns
mysql> SELECT column_name FROM table;
Retrieving unique output records
mysql> SELECT DISTINCT column_name FROM table;
Sorting
mysql> SELECT col1, col2 FROM table ORDER BY col2;
Backwards: SELECT col1, col2 FROM table ORDER BY col2 DESC;
Date calculations
mysql> SELECT CURRENT_DATE, (YEAR(CURRENT_DATE)-YEAR(date_col)) AS time_diff [FROM table];
MONTH(some_date) extracts the month value and DAYOFMONTH() extracts day.
Pattern Matching
mysql> SELECT * FROM table WHERE rec LIKE “blah%”;
(% is wildcard - arbitrary # of chars)
Find 5-char values: SELECT * FROM table WHERE rec like “_____”;
(_ is any single character)
Extended Regular Expression Matching
mysql> SELECT * FROM table WHERE rec RLIKE “^b$”;
(. for char, […] for char class, * for 0 or more instances
^ for beginning, {n} for repeat n times, and $ for end)
(RLIKE or REGEXP)
To force case-sensitivity, use “REGEXP BINARY”
Counting Rows
mysql> SELECT COUNT(*) FROM table;
Grouping with Counting
mysql> SELECT owner, COUNT(*) FROM table GROUP BY owner;
(GROUP BY groups together all records for each ‘owner’)
Selecting from multiple tables
(Example)
mysql> SELECT pet.name, comment FROM pet, event WHERE pet.name = event.name;
(You can join a table to itself to compare by using ‘AS’)
Currently selected database
mysql> SELECT DATABASE();
Maximum value
mysql> SELECT MAX(col_name) AS label FROM table;
Auto-incrementing rows
mysql> CREATE TABLE table (number INT NOT NULL AUTO_INCREMENT, name CHAR(10) NOT NULL);
mysql> INSERT INTO table (name) VALUES (”tom”),(”dick”),(”harry”);
Adding a column to an already-created table
mysql> ALTER TABLE tbl ADD COLUMN [column_create syntax] AFTER col_name;
Removing a column
mysql> ALTER TABLE tbl DROP COLUMN col;
(Full ALTER TABLE syntax available at mysql.com.)
Batch mode (feeding in a script)
# mysql -u user -p < batch_file
(Use -t for nice table layout and -vvv for command echoing.)
Alternatively: mysql> source batch_file;
Backing up a database with mysqldump
# mysqldump –opt -u username -p database > database_backup.sql
(Use ‘mysqldump –opt –all-databases > all_backup.sql’ to backup everything.)
Basic Tags
<html></html>
Creates an HTML document
<head></head>
Sets off the title and other information that isn’t displayed on the Web page itself
<body></body>
Sets off the visible portion of the document
Header Tags
<title></title>
Puts the name of the document in the title bar
Body Attributes
<body bgcolor=?>
Sets the background color, using name or hex value
<body text=?>
Sets the text color, using name or hex value
<body link=?>
Sets the color of links, using name or hex value
<body vlink=?>
Sets the color of followed links, using name or hex value
<body alink=?>
Sets the color of links on click
Text Tags
<pre></pre>
Creates preformatted text
<hl></hl>
Creates the largest headline
<h6></h6>
Creates the smallest headline
<b></b>
Creates bold text
<i></i>
Creates italic text
<tt></tt>
Creates teletype, or typewriter-style text
<cite></cite>
Creates a citation, usually italic
<em></em>
Emphasizes a word (with italic or bold)
<strong></strong>
Emphasizes a word (with italic or bold)
<font size=?></font>
Sets size of font, from 1 to 7)
<font color=?></font>
Sets font color, using name or hex value
Links
<a href=”URL”></a>
Creates a hyperlink
<a href=”mailto:EMAIL”></a>
Creates a mailto link
<a name=”NAME”></a>
Creates a target location within a document
<a href=”#NAME”></a>
Links to that target location from elsewhere in the document
Formatting
<p></p>
Creates a new paragraph
<p align=?>
Aligns a paragraph to the left, right, or center
<br>
Inserts a line break
<blockquote>
</blockquote>
Indents text from both sides
<dl></dl>
Creates a definition list
<dt>
Precedes each definition term
<dd>
Precedes each definition
<ol></ol>
Creates a numbered list
<li></li>
Precedes each list item, and adds a number
<ul></ul>
Creates a bulleted list
<div align=?>
A generic tag used to format large blocks of HTML, also used for stylesheets
Graphical Elements
<img src=”name”>
Adds an image
<img src=”name” align=?>
Aligns an image: left, right, center; bottom, top, middle
<img src=”name” border=?>
Sets size of border around an image
<hr>
Inserts a horizontal rule
<hr size=?>
Sets size (height) of rule
<hr width=?>
Sets width of rule, in percentage or absolute value
<hr noshade>
Creates a rule without a shadow
Tables
<table></table>
Creates a table
<tr></tr>
Sets off each row in a table
<td></td>
Sets off each cell in a row
<th></th>
Sets off the table header (a normal cell with bold, centered text)
Table Attributes
<table border=#>
Sets width of border around table cells
<table cellspacing=#>
Sets amount of space between table cells
<table cellpadding=#>
Sets amount of space between a cell’s border and its contents
<table width=# or %>
Sets width of table - in pixels or as a percentage of document width
<tr align=?> or <td align=?>
Sets alignment for cell(s) (left, center, or right)
<tr valign=?> or <td valign=?>
Sets vertical alignment for cell(s) (top, middle, or bottom)
<td colspan=#>
Sets number of columns a cell should span
<td rowspan=#>
Sets number of rows a cell should span (default=1)
<td nowrap>
Prevents the lines within a cell from being broken to fit
Frames
<frameset></frameset>
tag in a frames document; can also be nested in other framesets
<frameset rows=”value,value”>
Defines the rows within a frameset, using number in pixels, or percentage of w idth
<frameset cols=”value,value”>
Defines the columns within a frameset, using number in pixels, or percentage of width
<frame>
Defines a single frame - or region - within a frameset
<noframes></noframes>
Defines what will appear on browsers that don’t support frames
Frames Attributes
<frame src=”URL”>
Specifies which HTML document should be displayed
<frame name=”name”>
Names the frame, or region, so it may be targeted by other frames
<frame marginwidth=#>
Defines the left and right margins for the frame; must be equal to or greater than 1
<frame marginheight=#>
Defines the top and bottom margins for the frame; must be equal to or greater than 1
<frame scrolling=VALUE>
Sets whether the frame has a scrollbar; value may equal “yes,” “no,” or “auto. ” The default, as in ordinary documents, is auto.
<frame noresize>
Prevents the user from resizing a frame
Forms
For functional forms, you’ll have to run a CGI script. The HTML just creates the appearance of a form.
<form></form>
Creates all forms
<select multiple name=”NAME” size=?></select>
Creates a scrolling menu. Size sets the number of menu items visible before yo u need to scroll.
<option>
Sets off each menu item
<select name=”NAME”></select>
Creates a pulldown menu
<option>
Sets off each menu item
<textarea name=”NAME” cols=40 rows=8></textarea>
Creates a text box area. Columns set the width; rows set the height.
<input type=”checkbox” name=”NAME”>
Creates a checkbox. Text follows tag.
<input type=”radio” name=”NAME” value=”x”>
Creates a radio button. Text follows tag
<input type=text name=”foo” size=20>
Creates a one-line text area. Size sets length, in characters.
<input type=”submit” value=”NAME”>
Creates a Submit button
<input type=”image” border=0 name=”NAME” src=”name.gif”>
Creates a Submit button using an image
<input type=”reset”>
Creates a Reset button
Enable Directory Browsing
bc.. Options +Indexes
1. block a few types of files from showing
IndexIgnore *.wmv *.mp4 *.avi
Disable Directory Browsing
bc.. Options All -Indexes
Customize Error Messages
bc.. ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.html
Get SSI working with HTML/SHTML
bc.. AddType text/html .html
AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml
1. AddHandler server-parsed .htm
Change Default Page (order is followed!)
bc.. DirectoryIndex myhome.htm index.htm index.php
Block Users from accessing the site
bc..
order deny,allow
deny from 202.54.122.33
deny from 8.70.44.53
deny from .spammers.com
allow from all
Allow only LAN users
bc.. order deny,allow
deny from all
allow from 192.168.0.0/24
Redirect Visitors to New Page/Directory
bc.. Redirect oldpage.html http://www.domainname.com/newpage.html
Redirect /olddir http://www.domainname.com/newdir/
Block site from specific referrers
bc.. RewriteEngine on
RewriteCond %{HTTP_REFERER} site-to-block\.com [NC]
RewriteCond %{HTTP_REFERER} site-to-block-2\.com [NC]
RewriteRule .* – [F]
Block Hot Linking/Bandwidth hogging
bc.. RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ – [F]
Want to show a “Stealing is Bad” message too?
Add this below the Hot Link Blocking code:
bc. RewriteRule \.(gif|jpg)$ http://www.mydomain.com/dontsteal.gif [R,L]
Stop .htaccess (or any other file) from being viewed
bc..
order allow,deny
deny from all
Avoid the 500 Error
bc.. # Avoid 500 error by passing charset
AddDefaultCharset utf-8
Grant CGI Access in a directory
bc.. Options +ExecCGI
AddHandler cgi-script cgi pl
1. To enable all scripts in a directory use the following
2. SetHandler cgi-script
Password Protecting Directories
Use the .htaccess Password Generator and follow the brief instructions!
Change Script Extensions
bc. AddType application/x-httpd-php .gne
gne will now be treated as PHP files! Similarly, x-httpd-cgi for CGI files, etc.
Use MD5 Digests
Performance may take a hit but if thats not a problem, this is a nice option to turn on.
bc. ContentDigest On
The CheckSpelling Directive
From Jens Meiert: CheckSpelling corrects simple spelling errors (for example, if someone forgets a letter or if any character is just wrong). Just add CheckSpelling On to your htaccess file.
The ContentDigest Directive
As the Apache core features documentation says: “This directive enables the generation of Content-MD5 headers as defined in RFC1864 respectively RFC2068. The Content-MD5 header provides an end-to-end message integrity check (MIC) of the entity-body. A proxy or client may check this header for detecting accidental modification of the entity-body in transit.
Note that this can cause performance problems on your server since the message digest is computed on every request (the values are not cached). Content-MD5 is only sent for documents served by the core, and not by any module. For example, SSI documents, output from CGI scripts, and byte range responses do not have this header.”
To turn this on, just add ContentDigest On.
Save Bandwidth
bc.. # Only if you use PHP
php_value zlib.output_compression 16386
Turn off magic_quotes_gpc
bc.. # Only if you use PHP
php_flag magic_quotes_gpc off
Setup a Virtual Domain
NameVirtualHost *
<VirtualHost *>
DocumentRoot /web/example.com/www
ServerName www.example.com
ServerAlias example.com
CustomLog /web/example.com/logs/access.log combined
ErrorLog /web/example.com/logs/error.log
</VirtualHost>
Include another conf file
Include /etc/apache/virtual-hosts/*.conf
Hide apache version info
ServerSignature Off
ServerTokens Prod
Custom 404 Error message
ErrorDocument 404 /404.html
Create a virtual directory (mod_alias)
Alias /common /web/common
Permanent redirect (mod_alias)
Redirect permanent /old http://example.com/new
Create a cgi-bin
ScriptAlias /cgi-bin/ /web/cgi-bin/
Process .cgi scripts
AddHandler cgi-script .cgi
Add a directory index
DirectoryIndex index.cfm index.cfm
Turn off directory browsing
Options -Indexes
Turn on directory browsing
<Location /images>
Options +Indexes
</Location>
Create a new user for basic auth (command line)
htpasswd -c /etc/apacheusers
Apache basic authentication
AuthName “Authentication Required”
AuthType Basic
AuthUserFile /etc/apacheusers
Require valid-user
Only allow access from a specific IP
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Only allow access from your subnet
Order Deny,Allow
Deny from all
Allow from 176.16.0.0/16
Turn on the rewrite engine (mod_rewrite)
RewriteEngine On
Redirect /news/123 to /news.cfm?id=123
RewriteRule ^/news/([0-9]+)$ /news.cfm?id=$1 [PT,L]
Redirect www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com$1 [R=301,L]