Sorry, this page may not be displayed properly, because, your browser is not supporting Safe JavaScripts. 
Atikotek - Edu-WebDv-WebSrvr- Apache - .htaccess (1)(2)(3)(4)(5). Atikotek(1)(2)(3)(4)(5) | Go Back(1)(2)(3)(4)(5) | Search(1)(2)(3)(4)(5)  
  Forum  

Help, Tutorial On Apache Web Server Configuration Related Areas ...

(1)
Warning : Modifying existing default values will cause SSI or other errors or your site unavilable, so modification is not encouraged unless an error/problem occurs and approved by site-admin/webmaster. And, plz don't tell us, didn't warn you.

Any configuration that you would consider putting in a .htaccess file, can just as effectively be made in a <Directory> section in your main server configuration ("httpd.conf") file.

There are two main reasons to avoid the use of .htaccess files. The first of these, is, Apache Server's performance, (increased hard-drive & cpu usage). If your server using good/powerful processor(s), faster hard-drive and lots of RAM, then there's less to worry. My suggestion is to use hard-drive with lots of cache memory built into them. The second consideration is one of security. You are permitting users to modify server configuration, which may result in changes over which you have no control. Carefully consider whether you want to give your users this privilege. Note also that giving users less privileges than they need will lead to additional technical support requests.

Apache web servers have two main places for configuration information. Per-directory(/Local) ".htaccess" files overrides the httpd Config files ("httpd.conf") (typically located somewhere like /etc/httpd/ or, /etc/httpd/conf/ ).

(5)
Prevent viewing of .htaccess file :-
<Files  .htaccess>
  order allow,deny
  deny from all
  Satisfy All
</Files>

(7)
Prevent viewing of ".htaccess", ".log", ".comment" file :-
<Files  "^.*\.(log|comment|htaccess)">
  Order allow,deny
  Deny from all
  Satisfy All
</Files>

(9)
Allow SSI in .html files:
You may be on a server that requires files to end in .shtml for executing Server Side Includes(SSI) directive tags/commands. If you do not wish to use the .shtml extension, or, if you have added Server Side Include tags to your existing .htm or .html files. Add the following to your .htaccess file for proper parsing:
AddType  text/html  .shtml .shtm .htm .html
AddHandler  server-parsed  .shtml .shtm .htm .html
Caution : Files which must be parsed by the server before being displayed may not load as quickly as standard pages. If you use this code in your.htaccess file, the server will parse all .html and .htm pages, including those that do not contain any SSI includes. This could significantly slow the loading of pages which do not use the includes. Pages with graphics may become very slow to load. (Info of this paragraph obtained from here).

(11)
Enable SSI via .htaccess:
AddType  text/html  .shtml
AddHandler  server-parsed  .html
AddHandler  server-parsed  .shtml
Options Indexes FollowSymLinks Includes

(13)
If you cannot use SSI with your host, you can try and enable it via the following command in the .htaccess file:
AddType  text/html  .shtml
AddHandler  server-parsed  .shtml
Options Indexes FollowSymLinks Includes

(15)
Parsing PHP in .html Files:
To include PHP commands in your existing html files, you can append the below codes.
RemoveHandler  .html .htm
AddType  application/x-httpd-php  .php .php3 .phtml .htm .html

(17)
Preventing Directory Listing :-
If one of your directory contains files, but not an index file, then server displays entire contents of that directory. To prevent this...
IndexIgnore  *
You could just block the gif and jpg files for example:
IndexIgnore  *.gif  *.jpg
Prevent directory browsing:
IndexIgnore  */*
If your server is setup to prevent directory listing, but you want to list the directories by default, then add below code :
Options  +Indexes

(19)
Deny access to the users who are behind/using a specific Domain, and trying to access your GIF (*.gif), PNG (*.png), JPG (*.jpg) picture files.
<Files  "^.*\.([Gg][Ii][Ff]|[Pp][Nn][Gg]|[Jj][Pp][Gg])">
  Order Deny, Allow
  Deny from .BadGreedyPeoplesDomain.net
</Files>

(21)
Allow only your United Kingdom (uk) branch office's computer users, who are behind the ".guardian.co.uk" domain, to access a set of specific Files & Folders in your server, which starts with the letters "news_uk_".
<Files  news_uk_*>
  Order Allow, Deny
  Deny from all
  Allow from .guardian.co.uk
  Allow from .uk
</Files>

(23)
To block / stop SpamBots (Spammer Companies) who/which are stealing yours and your host's bandwidth, use below approach. Last line sends them off to the FBI, but you could also send them to a standard error page created by you. Block specific IP address or range.
RewriteEngine  on
RewriteBase  /
RewriteCond  %{HTTP_USER_AGENT}  ^EmailSiphon  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^EmailWolf  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^ExtractorPro  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla.*NEWT  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^Crescent  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^CherryPicker  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^[Ww]eb[Bb]andit  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^WebEMailExtrac.*  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^NICErsPRO  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^Teleport  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^Zeus.*Webster  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^Microsoft.URL  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^Wget  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^LinkWalker  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^sitecheck.internetseer.com  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^ia_archiver  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^DIIbot  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^psbot  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^EmailCollector  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^.*Ants.*  [OR]
RewriteCond  %{HTTP_USER_AGENT}  ^.*attach.*  [OR]
RewriteCond  %{REMOTE_ADDR}  ^123\.45\.67\.[8-9]$
RewriteRule  ^.*  -  [F]
RewriteCond  %{HTTP_REFERER}  ^http://www.iaea.org$
RewriteRule  /*  http://www.fbi.gov  [L,R]
RewriteRule  !^http://[^/.]\.atikotek.5gigs.com.*  -  [F]

(25)
If you want to stop Unwanted user-agent's (Spiders, Robots, Crawler, Browser, File-Download Manager Software) access to your files:
.htacces with single RewriteCond directive:
RewriteEngine On
RewriteCond  %{HTTP_USER_AGENT}  BlackWidow|Bot\ mailto:craftbot@yahoo.com|ChinaClaw|DISCo|Download\ Demon|eCatch|EirGrabber|EmailSiphon|Express\ WebPictures|ExtractorPro|EyeNetIE|FlashGet|GetRight|Go!Zilla|Go-Ahead-Got-It|GrabNet
RewriteRule  .*  -  [F,L]
(Info in this & below paragraph obtained from member "andreasfriedrich" @ webmasterworld.com)

(27)
.htaccess with multiple RewriteCond directives:
RewriteEngine  On
RewriteCond %{HTTP_USER_AGENT} BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} Download\ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} Express\ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} GrabNet [OR]
RewriteRule .* - [F,L]

(29)
Use "RewriteMap" to reduce the size of your ".htaccess" file:
RewriteEngine  On
RewriteMap  DenyContainer  txt:/path/to/Deny_List_Map.txt
RewriteCond  ${DenyContainer:%{HTTP_USER_AGENT}|NOT-FOUND}  !=NOT-FOUND  [OR]
RewriteCond  ${DenyContainer:%{REMOTE_HOST}|NOT-FOUND}  !=NOT-FOUND  [OR]
RewriteCond  ${DenyContainer:%{REMOTE_ADDR}|NOT-FOUND}  !=NOT-FOUND
RewriteRule  ^/.*  -  [F]
Create the map file "Deny_List_Map.txt" with below data. But creating different file for different type of data are better than one file.
## Deny_List_Map.txt
## ATTENTION! This is a map, not a list, even when we treat it as such.
## mod_rewrite parses it for key/value pairs, so at least a
## dummy value "-" must be present for each entry.
##
BlackWidow   -
Bot mailto:craftbot@yahoo.com   -
ChinaClaw   -
EmailCollector   -
Teleport   -
123.45.67.8   -
netvigator.com   -
sitecheck.internetseer.com   -
Your own Perl script (as external rewriting engine) can also be used to rewrite :
RewriteMap  DenyContainer  prg:/path/to/deny_list_map.pl
RewriteRule  ^/(.*)$  /${DenyContainer:$1}

(31)
Very good thing to do, if you want to lower your server's cpu resource usage:
Use a single RewriteCond directive in your .htaccess files.
Use multiple RewriteCond directives in your httpd.conf file.

(33)
If you want to block/deny access to all of your files to certain IP Blocks, or, domains, which are owned/operated by the spammer companies, then use below codes ...
<Files *>
  order deny,allow
  deny from  61.4.64.0/20
  deny from  63.148.99.224/27
  deny from  217.78.
  deny from  218.65.0.0/17
  deny from  219.147.174.0/24
  deny from  netvigator.com
  deny from  mail.whitepine-ventures.com
  deny from  boxpaper.com
</Files>

(35)
Deny access to IP Range from 24.265.32.5 to 24.265.32.122 to all your files:
SetEnvIf  Remote_Addr  ^24\.265\.32\.([5-9]|[1-9][0-9]|1[0-1][0-9]|12[0-2])  banlist1
<Files  ~  "^.*$">
  order  allow,deny
  allow  from  all
  deny  from  env=banlist1
</Files>
(Found previous paragraph info at corz.org)

(37)
Serve your compressed files correctly:
 Syntax:  AddEncoding MIME-enc extension [extension] ...
AddEncoding  x-gzip  gz
AddEncoding  x-compress  Z

(39)
RemoveEncoding directives : are processed after any AddEncoding directives, so it is possible they may undo the effects of the latter if both occur within the same directory configuration. It removes any encoding associations for files with the given extensions. This allows .htaccess files in subdirectories to undo any associations inherited from parent directories or the server config files.
 Syntax:  RemoveEncoding  extension [extension] ...
RemoveEncoding  .gz

(41)
If the server is not setup correctly to serve files with their proper types, then you can change that with below lines. If you incorporate files in your site which require browser plugins you may need to specify the mime-type. The AddType directive maps the given filename extensions onto the specified content type. MIME-type is the MIME type to use for filenames containing extension. This mapping is added to any already in force, overriding any mappings that already exist for the same extension. :
 Syntax:  AddType  MIME-type extension [extension] ...
AddType  text/plain  txt  –› AddType  application/java-archive  jar
AddType  audio/midi  mid    AddType  text/vnd.sun.j2me.app-descriptor  jad
AddType  image/jpeg  jpg    AddType  audio/x-pn-realaudio  ra
AddType  image/x-photoshop  psd    AddType  application/x-pmd  pmd
AddType  image/gif  gif    AddType  application/x-tar  tgz
AddType  image/x-icon  ico    AddType  application/vnd.rn-realmedia  rm
AddType  image/png  png –›   AddType  application/x-shockwave-flash  swf
(Left column continues in the right column. When you use those codes, add right column at bottom of left column).
For more registered MIME types, visit http://www.iana.org/assignments/media-typ es/index.html. The extension argument is case-insensitive, and can be specified with or without a leading dot.

(43)
RemoveType directive : removes any MIME type associations for files with the given extensions. This allows .htaccess files in subdirectories to undo any associations inherited from parent directories or the server config files. This action takes place after AddType.
 Syntax:  RemoveType  extension [extension] ...
RemoveType  .cgi

(45)
If you want to set one of your sub-folder as homepage for your cell/mobile phone, then add below code inside that folder's ".htaccess" file.
DirectoryIndex  index.wml
AddType  text/x-pcs-gcd  gcd
addtype  text/vnd.wap.wml  wml
addtype  application/vnd.wap.wmlc  wmlc
addtype  text/vnd.wap.wmlscript  wmls
addtype  application/vnd.wap.wmlscriptc  wmlsc
addtype  image/vnd.wap.wbmp  wbmp
AddType  audio/vnd.qcelp  qcp
addtype  text/x-hdml  hdml

(47)
AddHandler:

AddHandler maps the filename extensions extension to the handler handler-name. This mapping is added to any already in force, overriding any mappings that already exist for the same extension. For example, to activate CGI scripts with the file extension ".cgi", you might use:
 Syntax:  AddHandler  handler-name extension [extension] ...
AddHandler  cgi-script  .cgi

(49)
RemoveHandler directive removes any handler associations for files with the given extensions. This allows .htaccess files in subdirectories to undo any associations inherited from parent directories or the server config files.
 Syntax:  RemoveHandler  extension [extension] ...
RemoveHandler  .html

(51)
Modifying static content using a CGI script:
The following directives will cause requests for files with the html extension to trigger the launch of the "mysitefooter.pl" CGI script. Then the CGI script is responsible for sending the originally requested document (pointed to by the PATH_TRANSLATED environment variable) and making whatever modifications or additions are desired.
Action  add-footer  /cgi-bin/mysitefooter.pl
AddHandler  add-footer  .html

(53)
SetHandler :
When placed into an .htaccess file or a <Directory> or <Location> section, this directive forces all matching files to be parsed through the handler given by handler-name. You can override an earlier defined SetHandler directive by using the value None.
 Syntax:  SetHandler  handler-name|None
SetHandler  cgi-script
Above example will let the server treat all files under this .htaccess as cgi-script files, regardless of extension.
SetHandler specifies a handler to be used for all files in a directory or location. There are six built-in values for handler
  Handler _______ Description
  cgi-script ____ All files are treated as CGI scripts and processed by mod_cgi.
  imap-file _____ All files are treated as imagemap files and processed by mod_imap.
  send-as-is ____ Stronghold send all files without appending HTTP headers.
  server-info ___ All files are sent with server configuration information.
  server-status _ All files are sent with server status information.
  server-parsed _ All files are treated as server-parsed HTML, for server-side includes by mod_ssi.
  type-map ______ All files are treated as type maps for content negotiation by mod_negotiation.

(55)
Change your default directory page, or, re-arrange the default page serving order. Below code will make the file "filename.html" as first default file to be served by the web server :
DirectoryIndex  filename.html  index.cgi  index.pl  index.php  index.html  default.htm
When internet user goes to your site or in a folder, then Apache Web Server Software looks for files one after one, which are pre-defined/listed in its configuration file by the command/directive name "DirectoryIndex".
If you or your hosting company haven't modified the "DirectoryIndex" directive/command for configuring Apache Web Server, then apache looks for only one file index.html by default.
But a custom configuration, which is usually followed by many is like below
Options +FollowSymlinks
DirectoryIndex  index.html  index.htm  default.html  default.htm  index.php  index.php3  index.php4  index.phtml  index.php5  index.shtml  index.pl  index.cgi
So if you have "index.php" and "index.html" both file under any same sub-folder, and user hasn't specified any filename, then, according to the directive, index.html will be (executed/)delivered to the user's browser(/agent) software.
But when you're using php coded files, then php files should have priority over html. So a better configuration is
DirectoryIndex  index.cgi  index.pl  index.shtml  index.php  index.php4  index.php3  index.phtml  index.html  index.htm  default.htm  default.html

(57)
You may create and use your own custom error documents, to display in response to errors such as requests to non-existant files, by using the ErrorDocument directive.
ErrorDocument  404  /errors/File_Not_Found.html
ErrorDocument  403  /errors/Forbidden.html
ErrorDocument  500  /errors/Internal_Server_Error.html
ErrorDocument  401  /errors/Authorization_Required.html
ErrorDocument  400  /errors/Bad_Request.html

(59)
If you want to use/keep comment/notes inside the .htaccess file, then use "#" symbol :
# this is a commented-out line

(61)
Regular Expressions:
Patterns ("wildcards") are matched against(/replaced by) a string. Normal alphanumeric characters are treated as normal(no backslash/escape sequence required). Special characters:
. (full stop) - match any character. any single character.
* (asterix) - match zero or more of the previous/preceding symbol (some or none).
+ (plus) - match one or more of the previous symbol .
? (question) - match zero or one of the previous symbol .
\? (backslash-escape character-something) - match special characters. escape particular chars like ".[]()" etc.
\1  to \9 (backslash-number 1 to 9) - backreferences. Backreferences refer back to whatever occurred in the previous grouped expressions, in the order those grouped expressions occurred.
^ (caret) - match the start of a string .
$ (dollar) - match the end of a string .
[ set ] - match any one of the symbols inside the square braces.
( pattern ) - grouping, prioritized, remember what the pattern matched as a special variable .
| (pipe character) - (side1|side2) - alternation operator - matches data in one side of the pipe character out of two side data.
{} (curly braces) - pattern occurrence count. minimum/maximum occurance. Can contain max two set of numbers separated by comma(,) symbol. first must be no larger than the second, and both must be non-negative integers. "{,}" means the minimum/maximum is specified as zero/infinity, respectively.

(65)
Examples:
w+ matches "w", "www", "wwwwwww", but not "aaa".
[gh]+ matches, "g", "h", or any length combination of the two.
\.s?html? matches ".htm", ".shtm", ".html" or ".shtml" .
(.+)/2006/(.+) matches "Latest/2006/Jan/", and also stores "Latest" in $1 and "Jan/" in $2.
(Location)( )(top) matches "Location top".
w{3} matches "www".
"P(ijk)?Q" is equivalent to "PijkQ|PQ".
"(ijk)+" is equivalent to "(ijk)(ijk)*".

(67)
Redirects:

There are different ways of redirecting pages, through http-equiv, javascript, other server-side languages, or, .htaaccess. ( Remember, 5Gigs.com authority forbids you to use any URL forwarding or, shortening.) Note: To enable the rewriting engine for per-directory configuration files you need to set "RewriteEngine On" in these files and "Options FollowSymLinks" must be enabled. If your administrator has disabled override of FollowSymLinks for a user's directory, then you cannot use the rewriting engine. This restriction is needed for security reasons.
"permanent" - the resource has moved permanently, "temp" - it has temporarily moved elsewhere , "seeother" - the resource has been replaced , "gone" - it has been permanently removed. If no code is given a HTTP response of 302 (MOVED TEMPORARILY)("temp") is used.
Redirect   /olddirectory/oldfile.html   /newdirectory/newfile.html
Redirect   gone   /Loc5/Latest/TradeShowList/1997/
Redirect   seeother   /Loc2/Latest/TradeShowList/2004/   /Loc2/Latest/TradeShowList/2005/
Redirect   permanent   /Loc7/Latest/TradeShowList/1999/   http://www.mysubdomain.5gigs.com/Loc8/Latest/TradeShowList/1999/
Redirect   temp   /userdata/john/config.html   /userdata/sitemaintenance/notice.html

(69)
Many uses the mod_rewrite for short URL. shorter URL's are easier to remember and to type. When this short & easy URL
http://www.atikotek.5gigs.com/downld?file=free_games.zip
is used, below codes will transfer/serve the filename to "download.php", and it will let you download that file.
Options  +FollowSymlinks
RewriteEngine  On
RewriteRule  ^download(.*)   /public/files/games/download.php$1

(71)
Rewriting URL:
  Syntax:  RewriteEngine  on|off
  Syntax:  RewriteCond  TestString CondPattern
  Syntax:  RewriteOptions  Option
  Syntax:  RewriteBase  URL-path
  Syntax:  RewriteRule  Pattern Substitution

(73)
TestString contains plain text, RewriteRule backreferences, RewriteCond backreferences, RewriteMap expansions, Server-Variables, etc.

(75)
CondPattern is the condition pattern, it is a regular expression which is applied to the current instance of the TestString. TestString is evaluated and then matched against CondPattern. And remember that, CondPattern is a standard Extended Regular Expression with some additions.

(77)
All the rewriting rules are applied to the Substitution (in the order of definition in the config file). The URL is completely replaced by the Substitution and the rewriting process goes on until there are no more rules unless explicitly terminated by a L flag - see below. special substitution string named '-' which means: NO substitution! it is useful to provide rewriting rules which only match some URLs but do not performs substitution process. Can be used in conjunction with the C (chain) flag to be able to have more than one pattern to be applied before a substitution occurs. When using the NOT character to negate a pattern you cannot have grouped wildcard parts in the pattern. This is impossible because when the pattern does NOT match, there are no contents for the groups. In consequence, if negated patterns are used, you cannot use $N in the substitution string!
RewriteEngine  on
RewriteBase  /Latest
RewriteRule  test/printenv(.*)  cgi-bin/printenv$1

(79)
You only need to do the below code once per .htaccess file, "+FollowSymlinks" must be enabled for any ReWrite rules to work, its a security requirement of the rewrite engine:
Options  +FollowSymlinks
RewriteEngine  on

(84)
Few important things to remember: Rules in top folders apply to all the sub-folders, as long as, they don't have .htaccess inside them. This is known as "inheritance". But if you want some of your rules to be propagated/applied in that sub-folder and sub of sub, along with few new rules, then you must put those rules again in that sub-folder's .htaccess file with the sub-folder's name inside the code.
For example: you have below code in a "forum" folder's .htaccess file:
rewriterule  ^(.*)\.html$  http://www.atikotek.5gigs.com/forum/$1.php  [r=301,nc]
and now you want to use few more new rules along with the prev rule inside .htaccess inside the "admin" sub-folder, then rule should be changed to:
rewriterule  ^(.*)\.html$  http://www.atikotek.5gigs.com/forum/admin/$1.php  [r=301,nc]

(86)
Request for (static) html files can be redirected on-the-fly to dynamic php pages, even if that html don't exist in that sub-folder:
RewriteRule  ^(.*)\.html  $1.php  [nc]

(88)
Request for static html files can be ("permanently moved") redirected to dynamic php pages:
RewriteRule  ^(.*)\.html$  http://www.atikotek.Our2ndHost.com/$1.php  [r=301,nc]

(90)
conditional Rewrites:
Rewrite URL, when files could not be found:
RewriteCond  %{REQUEST_FILENAME}  !-f
RewriteRule  ^(.+)errata\.html?$  cgi-bin/errata/errata-html/$1
RewriteCond  %{REQUEST_FILENAME}  !-f
RewriteRule  images/barcode/(.*).gif  cgi-bin/barcode/mkgif?$1
Serve/select homepage based on user's client/browser/agent software, by using environment variable values:
RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla.*
RewriteRule  ^/$  /homepage.maxfeature.html  [L]
RewriteCond  %{HTTP_USER_AGENT}  ^Lynx.*
RewriteRule  ^/$  /homepage.minfeature.html  [L]
RewriteRule  ^/$  /homepage.stdfeature.html  [L]

(95)
Server-Variables:
They are used in this format/way %{ NAME_OF_VARIABLE } .
HTTP headers : Connection & Request : Server Internals : System Stuff :
HTTP_USER_AGENT REMOTE_ADDR DOCUMENT_ROOT TIME_YEAR
 HTTP_REFERER  REMOTE_HOST  SERVER_ADMIN  TIME_MON
 HTTP_COOKIE  REMOTE_USER  SERVER_NAME  TIME_DAY
 HTTP_FORWARDED  REMOTE_IDENT  SERVER_ADDR  TIME_HOUR
 HTTP_HOST  REQUEST_METHOD  SERVER_PORT  TIME_MIN
 HTTP_PROXY_CONNECTION  SCRIPT_FILENAME  SERVER_PROTOCOL  TIME_SEC
 HTTP_ACCEPT  PATH_INFO  SERVER_SOFTWARE  TIME_WDAY
   QUERY_STRING    TIME
   AUTH_TYPE    
specials:
API_VERSION
 THE_REQUEST
 REQUEST_URI
 REQUEST_FILENAME
 IS_SUBREQ

(97)
RewriteRule backreferences: $N . provide access to the grouped parts (parenthesis!) of the pattern from the corresponding RewriteRule directive (the one following the current bunch of RewriteCond directives). Back-references are $N (N=0..9) identifiers which will be replaced by the contents of the Nth group of the matched Pattern.

(99)
RewriteCond backreferences: %N . provide access to the grouped parts (parentheses!) of the pattern from the last matched RewriteCond directive in the current bunch of conditions. %N (N=1..9).

(104)
Condition Pattern :
'<CondPattern' (is lexically lower) . '>CondPattern' (is lexically greater) . '=CondPattern' (is lexically equal) . '-d' (is directory) . '-f' (is regular file) . '-s' (is regular file with size) . '-l' (is symbolic link) . '-F' (is existing file via subrequest) . '-U' (is existing URL via subrequest) . prefix the pattern string with a '!' character (exclamation mark), if you want to specify a non-matching pattern or, to negate their meaning.

(106)
[flags] flags can be added/appended after Condition Pattern . 'nocase| NC' (no case) . 'ornext| OR' (or next condition) . 'redirect| R [=code]' (force redirect) . 'forbidden| F' (force URL to be forbidden) (HTTP response 403). 'gone| G' (force URL to be gone) (410) . 'proxy| P' (force proxy) . 'last| L' (last rule) . 'next| N' (next round) . 'chain| C' (chained with next rule) . 'type| T=MIME-type' (force MIME type) . 'nosubreq| NS' (used only if no internal sub-request) . 'qsappend| QSA' (query string append) . 'noescape| NE' (no URI escaping of output) . 'passthrough| PT' (pass through to next handler) . 'skip| S=num' (skip next rule(s)) . 'env| E=VAR:VAL' (set environment variable) . Multiple flags can be used by separating them with (,)comma. Warning : But be careful not to create an infinite loop, by using the flag "N"(next round) unwisely.

(108)
  ?     0 or 1 of the preceding text
  *     0 or N of the preceding text (N > 0)
  +     1 or N of the preceding text (N > 1)

(110)
Enable Compression and Save bandwidth with .htaccess:
Enables PHP's built-in transparent zlib compression for all your files. It works only when data being served/output by the PHP module. If you write/design your web pages with this in mind, you can use php echo statements and includes for your plain html output and just compress everything. But using the compression (mod_gzip / mod_deflate) library to perform on-the-fly compression of HTML/PHP/etc documents is better than below method, but many Host ISP doesn't allow it. If you don't have access to enable mod_gzip yourself, and your host wont do it for you (there's not many reasons why they shouldn't if you ask nicely) then there's two alternatives, that can produce similar results.
<ifModule  mod_php4.c>
  php_value  zlib.output_compression  16386
</ifModule>
or this,
<ifModule mod_php4.c>
  <FilesMatch  "^.*\.(php|html?)$">
   php_value  zlib.output_compression  4096
   php_flag  zlib.output_compression  on
   php_value  zlib.output_compression_level  5
   php_value  zlib.output_compression  4096
   php_value  output_handler  ob_gzhandler
  </FilesMatch>
</ifModule>

(112)
Or, use below code to compress only html & php files.
<FilesMatch  "\.(php|html?)$">
  php_value  zlib.output_compression  4096
</FilesMatch>
(Similar info like the previous paragraph can be found at corz.org).
Or, use below code
php_value  output_handler  ob_gzhandler

(114)
Add the below code as first line of php parsed pages. You cannot use both ob_gzhandler() and zlib.output_compression. Also note that using zlib.output_compression is preferred over ob_gzhandler().
<?php  ob_start ("ob_gzhandler");  ?>

(116)
Serve your CSS, JS, HTML, PHP, etc (PHP handler parsed) files (gzip) compressed & faster toward the user agent (browser) software. Add below codes at the beginning/top of those files. (Although 1st and last line are also enough to make it work) :
<?php  ob_start ("ob_gzhandler");
header ("Content-type: text/css; charset: UTF-8");
header ("Cache-Control: must-revalidate");
$offset = 60 * 60 ;
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header ($ExpStr);
?>
You can replace the above coding lines from 4 to 6 by below one line code,
header ('Expires: ' . gmdate ('D, d M Y H:i:s', time ()+60*60) . ' GMT');
Above codes are for CSS files, for JS, change "Content-type:" line ( #2 ) into below line,
header("Content-type: application/x-javascript; charset: UTF-8");
You should add below codes at the end of those files, as well. (Compression will still work, even if you don't include)
<?php  ob_end_flush();  ?>   Or, this <?php  ob_flush();  ?>
To make CSS, JS, etc files PHP parsed, add/modify like below in .htaccess
AddHandler  application/x-httpd-php  .php .css .js
AddHandler  server-parsed  .shtml .shtm .htm .html

(118)
Within php.ini (usually /etc/php.ini), add the following lines to activate GZIP compression (*nix Only)
# GZIP COMPRESSION
#
output_handler  =  ob_gzhandler

(121)
Enable mod_gzip compression:
"mod_gzip" uses gzip compresson.
# if httpd.conf already have below line, then no need to add
LoadModule  gzip_module  modules/mod_gzip.so
# if httpd.conf already contain below block, then no need to add
<IfModule  mod_gzip.c>
mod_gzip_on  Yes
mod_gzip_minimum_file_size  300
mod_gzip_maximum_file_size  0
mod_gzip_maximum_inmem_size  100000
mod_gzip_item_include  file  .htm$
mod_gzip_item_include  file  .html$
mod_gzip_item_include  file  .shtml$
mod_gzip_item_include  file  .shtm$
mod_gzip_item_include  file  .jsp$
mod_gzip_item_include  file  .php$
mod_gzip_item_include  file  .pl$
mod_gzip_item_include  file  .cgi$
mod_gzip_item_include  mime  text/.*
mod_gzip_item_include  mime  ^application/x-httpd-php
mod_gzip_item_include  mime  httpd/unix-directory
mod_gzip_item_include  mime  ^application/postscript$
mod_gzip_item_include  mime  ^application/ms.*$
mod_gzip_item_include  mime  ^application/vnd.*$
mod_gzip_item_include  handler  ^perl-script$
mod_gzip_item_include  handler  ^server-status$
mod_gzip_item_include  handler  ^server-info$
mod_gzip_item_exclude  file  .css$
mod_gzip_item_exclude  file  .js$
mod_gzip_item_exclude  mime  ^application/x-javascript$
mod_gzip_item_exclude  mime  ^image/.*$
mod_gzip_item_exclude  mime  ^application/pdf$
mod_gzip_item_exclude  file  /err/Authorization_Required.html
mod_gzip_item_exclude  file  /err/File_Not_Found.html
mod_gzip_item_exclude  file  /err/Internal_Server_Error.html
mod_gzip_item_exclude  file  /err/Forbidden.html
mod_gzip_item_exclude  file  /err/Bad_Request.html
mod_gzip_dechunk  yes
mod_gzip_temp_dir  /tmp
mod_gzip_keep_workfiles  No
mod_gzip_can_negotiate  yes
</IfModule>
# if httpd.conf already have below line, then no need to add
# Extra Modules
AddModule  mod_gzip.c
If you're having trouble compiling mod_gzip.so, check to see if it has right permission. You may use below command to give it right permission
chmod  755  mod_gzip.c

You can turn on and off mod_gzip per directory in the .htaccess file if needed for compatibility:

(125)
Enable "mod_deflate" for compression:
"mod_deflate" uses ZLIB compression. Please check this site http://webauthv3.stanford.edu/manual/m od/mod_deflate.html. Below codes (in "httpd.conf") enables the automatic GZIP-encoding of all MIME-types, except image and PDF files.
SetOutputFilter  DEFLATE
SetEnvIfNoCase  Request_URI  \.(?:gif|jpe?g|png)$  no-gzip  dont-vary
SetEnvIfNoCase  Request_URI  \.pdf$  no-gzip  dont-vary
SetEnvIfNoCase  Request_URI  \.(?:exe|t?gz|zip|bz2|sit|rar)$  no-gzip  dont-vary
Enable "mod_deflate" from "httpd.conf"
<IfDefine  APACHE2>
<IfModule  mod_deflate.c>
<Directory  "/your-server-root/manual">
  SetEnv  gzip-only-text/html  1
  SetOutputFilter  DEFLATE
</Directory>
</IfModule>
<IfModule  mod_deflate.c>
# DeflateFilterNote - Set a note to report on compression ratio
  DeflateFilterNote  deflate_ratio
  LogFormat  "%h %l %u %t \"%r\" %>s %b mod_deflate: %{deflate_ratio}n pct." common_with_deflate_info
  CustomLog logs/deflate.log  common_with_deflate_info
# Set the Deflate window size (1-15)
  DeflateWindowSize  10
# Set the Deflate Memory Level (1-9)
  DeflateMemLevel  6
# Here is an example of enabling compression for the Apache documentation:
  <Location  "/manual">
   SetEnv  gzip-only-text/html  1
   SetOutputFilter  DEFLATE
  </Location>
</IfModule>
</IfDefine>

(128)
Below code in htaccess:
<CompressMatch  "\.(htm?|jsp|php)$">
</CompressMatch>

(131)
Test if gzip_gzip compression working or not, at below sites http://leknor.com/code/gziped.php , or, http://www.desilva.biz/gzip-test.php , or, http://www.pipeboost.com/report.asp , or, http://www.philiweb.com/accueil.php?pn=utile/testgzip.php. Test your Web browser software to see if it supports compressed HTML at http://www.schroepl.net/cgi-bin/http_trace.pl.

(133)
Preventing hot-linking of images :-
To stop people from using your images on their site while the image is still on your site (stealing your valuable bandwidth), add the following to the .htaccess file:
RewriteEngine  On
RewriteCond  %{HTTP_REFERER}  !^$
RewriteCond  %{HTTP_REFERER}  !^http://(www\.)?atikotek\.5gigs\.com/.*$  [NC]
RewriteRule  \.(gif|jpg|png)$  -  [F]
Last line can be like below, if you want to show a different picture, whenever anyone try to hotlink / directlink :
RewriteRule  .*\.(gif|jpg|png)$  http://www.atikotek.5gigs.com/pic/nohotlink.png  [nc]
For example, to protect direct/hot linking of images or other files like wav, midi, mp3, mpeg, etc inside the "images" folder, located under your web site's root directory, you would use below code, in the .htaccess file located at your web site's root directory:
RewriteEngine  On
RewriteCond  %{HTTP_REFERER}  !^$
RewriteCond  %{HTTP_REFERER}  !^http://(www\.)?atikotek\.5gigs\.com/images/.*$  [NC]
RewriteRule  .*\.(gif|jpe?g|png|bmp|ico|wav|ram?|midi?|mpe?g?|avi)$  -  [F]
If we want to protect our picture/graphics/media stream files inside any first subdirectory from being direct linked / hotlinked, then we can replace 3rd line from above codes with the below line :
RewriteCond  %{HTTP_REFERER}  !^http://(www\.)?atikotek\.5gigs\.com/.*/.*$  [NC]

(135)
Test your images, if they are hotlinkable / direct linkable or not, at here http://altlab.com/hotlinkchecker.php.

(137)
Time-Dependend Rewriting:
There are a lot of variables named TIME_xxx for rewrite conditions. In conjunction with the special lexicographic comparison patterns <STRING, >STRING and =STRING we can do time-dependend redirects:
RewriteEngine  On
RewriteCond  %{TIME_HOUR}%{TIME_MIN}  >0700
RewriteCond  %{TIME_HOUR}%{TIME_MIN}  <1900
RewriteRule  ^index\.html$  index.day.html
RewriteRule  ^index\.html$  index.night.html

(141)
Force the use of www Canonical Hostnames:
if you wish to force the use of "www.atikotek.5gigs.com" instead of "atikotek.5gigs.com", then use below codes. Valid for sites running in port 80.
RewriteCond  %{HTTP_HOST}  !^atikotek\.5gigs\.com  [NC]
RewriteCond  %{HTTP_HOST}  !^$
RewriteRule  ^/(.*)  http://www.atikotek.5gigs.com/$1  [L,R]

(145)
Redirect inside the folder, if Trailing Slash is missing:
You can put below codes in the top-level .htaccess file of homedir (/) or into a sub-folder (/Loc2/).
RewriteEngine  On
RewriteBase  /Loc2/
RewriteCond  %{REQUEST_FILENAME}  -d
RewriteRule  ^(.+[^/])$  $1/  [R]

(148)
Redirect Failing URLs To Other Webserver:
This uses the URL look-ahead feature of mod_rewrite. The result is that this will work for all types of URLs and is a safe way. But using a ErrorDocument CGI-script is better. Below codes will not let you use anchor, like "url#anchor".
RewriteEngine  On
RewriteCond  %{REQUEST_URI}  !-U
RewriteRule  ^(.+)  http://atikotek.100free.com/$1

(153)
Extended Redirection (ErrorDocument CGI-script)(by using RewiteRule & CGI-script):
Create a new URL scheme xredirect: by the following per-server config-line (should be one of the last rewrite rules). This will force all URLs prefixed with "xredirect:" to be piped through the "nph-xredirect.cgi" program. When Apache's uri_escape() function uses the mod_rewrite, it escapes/ignores the hash character, to prevent that, we need to create a NPH-CGI script (NPH=non-parseable headers) which will do the redirect by itself, without missing any char.
RewriteRule  ^xredirect:(.+)  /path/to/nph-xredirect.cgi/$1  [T=application/x-httpd-cgi,L]
Now create the "nph-xredirect.cgi" file with below codes. it will provide functionality to do redirects to all URL schemes, including the one which are not directly accepted by mod_rewrite.
#!/path/to/perl
## nph-xredirect.cgi - - NPH/CGI script for extended redirects
## Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.
$| = 1; $url = $ENV{'PATH_INFO'};
print "HTTP/1.0 302 Moved Temporarily\n";
print "Server: $ENV{'SERVER_SOFTWARE'}\n";
print "Location: $url\n";
print "Content-type: text/html\n";
print "\n";
print "<html>\n"; print "<head>\n";
print "<title>302 Moved Temporarily (EXTENDED)</title>\n";
print "</head>\n";
print "<body>\n"; print "<h1>Moved Temporarily (EXTENDED)</h1>\n";
print "The document has moved <a HREF=\"$url\">here</a>.<p>\n";
print "</body>\n";
print "</html>\n";
##EOF##
It can be implemented like this:
RewriteRule  ^anyurl  xredirect:news:newsgroup
RewriteRule  ^anyurl  xredirect:http://atikotek.100free.com/index.html#copyright
another example:
RewriteEngine  on
RewriteCond  %{REQUEST_URI}  !-U
RewriteRule  ^(.+)  xredirect:http://atikotek.100free.com/$1
Do not use [R] or [R,L] at the end because the "xredirect:" need to be expanded later by those special "pipe through" rule, mentioned above.


- Authors : Md Ashfaq & Magnet Stone. ( June 25th, 2005 ).


Learn more about the ".htaccess" file at http://httpd.apache.org/docs/howto/htaccess.htm l , http://www.altaway.com/support/htaccess.html , http://usertools.plus.net/tutorials/id/5 , http://www.netmore.net/mini_htaccess.shtml , http://help.mindspring.com/webhelp/resources/powertips/accessindex.htm , http://ecaimaps.berkeley.edu/manual/howto/htaccess.html , http://mindprod.com/jgloss/htaccess.html , http://www.webmasterworld.com/forum13/687.htm , http://free.prohosting.com/~sampieri/freefaq/g_htaccess.shtml , http://httpd.apache.org/docs-2.0/mod/mod_mime.html .

Learn more about mod_rewrite at http://httpd.apache.org/docs/mod/mod_rewrite.html , http://httpd.apache.org/docs/misc/rewritegui de.html .

Learn more about SSI at http://httpd.apache.org/docs/howto/ssi.html .

Learn more about mod_mime module (MIME=Multipurpose Internet Mail Extensions) at http://httpd.apache.org/docs/mod/mod_mime.html .

Learn more about MIME types at http://www.webhelpinghand.com/htaccess_mime.htm , http://www.seas.upenn.edu/cets/answers/addty pe.html .

Learn more about "regular expressions" at http://etext.lib.virginia.edu/ services/helpsheets/unix/regex.html , http://gnosis.cx/publish/programmi ng/regular_expressions.html .

Learn more about User-Agents (Spiders, Robots, Crawler, Browser, File Downloading Client Software, etc): http://www.psychedelix.com/agents.html , PHP Spider Trap http://www.webmasterworld.com/forum88/3104.htm .

Learn more about how to enable compression for faster loading of webpages http://www.i4net.tv/marticle /get.php?action=getarticle&articleid=12 , http://i4net.tv/marticle/get.php?action=getarticle&articleid=21 , Install mod_gzip http://schroepl.net/projekte/mod_gzip/install. htm .

- Last Updated Partially on August 1, 2005.

DISCUSS  FURTHER  ON  THIS  ARTICLE  HERE
OR,  VISIT  HERE  FOR  MORE  INFORMATION
.

You must have to agree Legal Terms & Policy(1) (2) (3) (4) (5), before using this site.  Thankyou for visiting.  Contact Info(1) (2) (3) (4) (5).  Hosted By : 100Free.com  

Copyright © 2000 - Atikotek. All Rights Reserved.
All ®Registered, ©Copyrights and ™Trademarks referred herein are the property of their respective owners.

Models, Models, Models! Free Modeling Portfolio! ModelCoast. Photographers! Free Photographic Portfolios. Imagegods. Visit The Best Free Image Hosting.