|
webhosting |
| 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 :-
(7) Prevent viewing of ".htaccess", ".log", ".comment" file :-
(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:
(11) Enable SSI via .htaccess:
(13) If you cannot use SSI with your host, you can try and enable it via the following command in the .htaccess file:
(15) Parsing PHP in .html Files: To include PHP commands in your existing html files, you can append the below codes.
(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.
(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_".
(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.
(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:
(27) .htaccess with multiple RewriteCond directives:
(29) Use "RewriteMap" to reduce the size of your ".htaccess" file:
(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 ...
(35) Deny access to IP Range from 24.265.32.5 to 24.265.32.122 to all your files:
(37) Serve your compressed files correctly: Syntax: AddEncoding MIME-enc extension [extension] ...
(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] ...
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.
(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.
(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
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.
(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.
(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.
(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!
(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:
(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:
(95) Server-Variables: They are used in this format/way %{ NAME_OF_VARIABLE } .
(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.
(112) Or, use below code to compress only html & php files.
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) :
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
(118) Within php.ini (usually /etc/php.ini), add the following lines to activate GZIP compression (*nix Only)
(121) Enable mod_gzip compression: "mod_gzip" uses gzip compresson.
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.
(128) Below code in htaccess:
(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:
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:
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:
(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.
(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/).
(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".
(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.
- 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 : FateBack.com ( LidoNet.Net & MacleNet.com ) |
|
Copyright © 2000 -
Atikotek. All Rights Reserved. All ®Registered, ©Copyrights and ™Trademarks referred herein are the property of their respective owners. |