Movatterモバイル変換


[0]ホーム

URL:


FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Htaccess File Sample

htaccess file sampleAn attempt to create adefault skeleton .htaccess file with the very best apache htaccess examples... Updated semi-frequently based on detailed info from theApache htaccess tutorial.

NOTE:
Check out and use theGoogle 404 Error Page.

Sample Htaccess File

If you see any room for improvement, or if you can add something than go ahead and comment and I will definately give it a look for possible inclusion.

MAIN SETTINGS AND OPTIONS

### MAIN SETTINGS AND OPTIONS# Options: ALL,FollowSymLinks,Includes,IncludesNOEXEC,SymLinksIfOwnerMatch

MAIN DEFAULTS

### MAIN DEFAULTSOptions +ExecCGI -IndexesDirectoryIndex index.html index.htm index.phpDefaultLanguage en-USAddDefaultCharset UTF-8ServerSignature Off

ENVIRONMENT VARIABLES

### ENVIRONMENT VARIABLESSetEnv PHPRC /webroot/includesSetEnv TZ America/Las_VegasSetEnv SERVER_ADMIN webmaster@domain.tld

MIME TYPES

### MIME TYPESAddType video/x-flv .flvAddType application/x-shockwave-flash .swfAddType image/x-icon .ico

FORCE FILE TO DOWNLOAD INSTEAD OF APPEAR IN BROWSER

### FORCE FILE TO DOWNLOAD INSTEAD OF APPEAR IN BROWSERAddType application/octet-stream .mov .mp3 .zip

ERRORDOCUMENTS

### ERRORDOCUMENTS#-> http://askapache.com/htaccess/apache-status-code-headers-errordocument.html

1xx ErrorDocuments

ErrorDocument 100 /error-100/ErrorDocument 101 /error-101/ErrorDocument 102 /error-102/

2xx ErrorDocuments

ErrorDocument 200 /error-200/ErrorDocument 201 /error-201/ErrorDocument 202 /error-202/ErrorDocument 203 /error-203/ErrorDocument 204 /error-204/ErrorDocument 205 /error-205/ErrorDocument 206 /error-206/ErrorDocument 207 /error-207/

4xx ErrorDocuments

ErrorDocument 400 /error-400/ErrorDocument 401 /error-401/ErrorDocument 402 /error-402/ErrorDocument 403 /error-403/ErrorDocument 404 /error-404/ErrorDocument 405 /error-405/ErrorDocument 406 /error-406/ErrorDocument 407 /error-407/ErrorDocument 408 /error-408/ErrorDocument 409 /error-409/ErrorDocument 410 /error-410/ErrorDocument 411 /error-411/ErrorDocument 412 /error-412/ErrorDocument 413 /error-413/ErrorDocument 414 /error-414/ErrorDocument 415 /error-415/ErrorDocument 416 /error-416/ErrorDocument 417 /error-417/ErrorDocument 418 /error-418/ErrorDocument 419 /error-419/ErrorDocument 420 /error-420/ErrorDocument 421 /error-421/ErrorDocument 422 /error-422/ErrorDocument 423 /error-423/ErrorDocument 424 /error-424/ErrorDocument 425 /error-425/ErrorDocument 426 /error-426/

5xx ErrorDocuments

ErrorDocument 500 /error-500/ErrorDocument 501 /error-501/ErrorDocument 502 /error-502/ErrorDocument 503 /error-503/ErrorDocument 504 /error-504/ErrorDocument 505 /error-505/ErrorDocument 506 /error-506/ErrorDocument 507 /error-507/ErrorDocument 508 /error-508/ErrorDocument 509 /error-509/ErrorDocument 510 /error-510/

Add Languages

AddLanguage aa .aa # AfarAddLanguage ab .ab # AbkhazianAddLanguage af .af # AfrikaansAddLanguage am .am # AmharicAddLanguage ar .ar # ArabicAddLanguage as .as # AssameseAddLanguage ay .ay # AymaraAddLanguage az .az # AzerbaijaniAddLanguage ba .ba # BashkirAddLanguage be .be # ByelorussianAddLanguage bg .bg # BulgarianAddLanguage bh .bh # BihariAddLanguage bi .bi # BislamaAddLanguage bn .bn # Bengali; BanglaAddLanguage bo .bo # TibetanAddLanguage br .br # BretonAddLanguage ca .ca # CatalanAddLanguage co .co # CorsicanAddLanguage cs .cs # CzechAddLanguage cy .cy # WelshAddLanguage da .da # DanishAddLanguage de .de # GermanAddLanguage dz .dz # BhutaniAddLanguage el .el # GreekAddLanguage en .en # EnglishAddLanguage eo .eo # EsperantoAddLanguage es .es # SpanishAddLanguage et .et # EstonianAddLanguage eu .eu # BasqueAddLanguage fa .fa # PersianAddLanguage fi .fi # FinnishAddLanguage fj .fj # FijiAddLanguage fo .fo # FaeroeseAddLanguage fr .fr # FrenchAddLanguage fy .fy # FrisianAddLanguage ga .ga # IrishAddLanguage gd .gd # Scots GaelicAddLanguage gl .gl # GalicianAddLanguage gn .gn # GuamniAddLanguage gu .gu # GujaratiAddLanguage ha .ha # HausaAddLanguage he .he # HebrewAddLanguage hi .hi # HindiAddLanguage hr .hr # CroatianAddLanguage hu .hu # HungarianAddLanguage hy .hy # ArmenianAddLanguage ia .ia # InterlinguaAddLanguage id .id # IndonesianAddLanguage ie .ie # lnteriingueAddLanguage ik .ik # KnupiakAddLanguage is .is # IcelandicAddLanguage it .it # ItalianAddLanguage iu .iu # Inuktitut (Eskimo)AddLanguage ja .ja # JapaneseAddLanguage jw .jw # JavaneseAddLanguage ka .ka # GeorgianAddLanguage kk .kk # KazakhAddLanguage kl .kl # GreaenlandicAddLanguage km .km # CambodianAddLanguage kn .kn # KannadaAddLanguage ko .ko # KoreanAddLanguage ks .ks # KashmiriAddLanguage ku .ku # KurdishAddLanguage ky .ky # KirghizAddLanguage la .la # LatinAddLanguage ln .ln # LingalaAddLanguage lo .lo # LaothianAddLanguage lt .lt # LithuainnianAddLanguage lv .lv # Latvian, LettishAddLanguage mg .mg # MalagasyAddLanguage mi .mi # MaoriAddLanguage mk .mk # MacedonianAddLanguage ml .ml # MalayalamAddLanguage mn .mn # MongolianAddLanguage mo .mo # MoldavianAddLanguage mr .mr # MarathiAddLanguage ms .ms # MalayAddLanguage mt .mt # MalteseAddLanguage my .my # BurmeseAddLanguage na .na # NauruAddLanguage ne .ne # NepaliAddLanguage nl .nl # DutchAddLanguage no .no # NorwegianAddLanguage oc .oc # OccitanAddLanguage om .om # (Afan) OromoAddLanguage or .or # OriyaAddLanguage pa .pa # PunjabiAddLanguage pl .po # Polish (use .po instead .pl to avoid problems with perl files)AddLanguage ps .ps # Pashto, PushtoAddLanguage pt .pt # PortugueseAddLanguage qu .qu # OuechuaAddLanguage rm .rm # Rhaeto-RomanceAddLanguage rn .rn # KirundiAddLanguage ro .ro # RomanianAddLanguage ru .ru # RussianAddLanguage rw .rw # Kinya, RwandaAddLanguage sa .sa # SanskritAddLanguage sd .sd # SindhiAddLanguage sg .sg # SangroAddLanguage sh .sh # Serbo-CroatianAddLanguage si .si # SinghaleseAddLanguage sk .sk # SlovakAddLanguage sl .sl # SlovenianAddLanguage sm .sm # SamoanAddLanguage sn .sn # ShonaAddLanguage so .so # SomaliAddLanguage sq .sq # AlbanianAddLanguage sr .sr # SerbianAddLanguage ss .ss # SiswatiAddLanguage st .st # SesothoAddLanguage su .su # SundaneseAddLanguage sv .sv # SwedishAddLanguage sw .sw # SwahiliAddLanguage ta .ta # TamilAddLanguage te .te # TeguluAddLanguage tg .tg # TajikAddLanguage th .th # ThaiAddLanguage ti .ti # TigrinyaAddLanguage tk .tk # TurkmenAddLanguage tl .tl # TagalogAddLanguage tn .tn # SetswanaAddLanguage to .to # TongaAddLanguage tr .tr # TurkishAddLanguage ts .ts # TsongaAddLanguage tt .tt # TatarAddLanguage tw .tw # TwiAddLanguage ug .ug # UigurAddLanguage uk .uk # UkrainianAddLanguage ur .ur # UrduAddLanguage uz .uz # UzbekAddLanguage vi .vi # VietnameseAddLanguage vo .vo # VolapuekAddLanguage wo .wo # WolofAddLanguage xh .xh # XhosaAddLanguage yi .yi # YiddishAddLanguage yo .yo # YorubaAddLanguage za .za # ZhuangAddLanguage zh .zh # ChineseAddLanguage zu .zu # Zulu

SCRIPTING, ACTION, ADDHANDLER

### SCRIPTING, ACTION, ADDHANDLER# Handlers be builtin, included in a module, or added with Action directive# default-handler: default, handles static content (core)#      send-as-is: Send file with HTTP headers (mod_asis)#      cgi-script: treat file as CGI script (mod_cgi)#       imap-file: Parse as an imagemap rule file (mod_imap)#     server-info: Get server config info (mod_info)#   server-status: Get server status report (mod_status)#        type-map: type map file for content negotiation (mod_negotiation)#  fastcgi-script: treat file as fastcgi script (mod_fastcgi)#-> https://www.askapache.com/php/custom-phpini-tips-and-tricks/## PARSE AS CGIAddHandler cgi-script .cgi .pl .spl## RUN PHP AS APACHE MODULEAddHandler application/x-httpd-php .php .htm## RUN PHP AS CGIAddHandler php-cgi .php .htm## CGI PHP WRAPPER FOR CUSTOM PHP.INIAddHandler phpini-cgi .php .htmAction phpini-cgi /cgi-bin/php5-custom-ini.cgi## FAST-CGI SETUP WITH PHP-CGI WRAPPER FOR CUSTOM PHP.INIAddHandler fastcgi-script .fcgiAddHandler php-cgi .php .htmAction php-cgi /cgi-bin/php5-wrapper.fcgi## CUSTOM PHP CGI BINARY SETUPAddHandler php-cgi .php .htmAction php-cgi /cgi-bin/php.cgi## PROCESS SPECIFIC FILETYPES WITH CGI-SCRIPTAction image/gif /cgi-bin/img-create.cgi## CREATE CUSTOM HANDLER FOR SPECIFIC FILE EXTENSIONSAddHandler custom-processor .sspAction custom-processor /cgi-bin/myprocessor.cgi

HEADERS, CACHING AND OPTIMIZATION

### HEADERS, CACHING AND OPTIMIZATION#      300   5 M#     2700  45 M#     3600   1 H#    54000  15 H#    86400   1 D#   518400   6 D#   604800   1 W#  1814400   3 W#  2419200   1 M# 26611200  11 M# 29030400   1 Y (never expire)### HEADER CACHING#-> https://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching/   Header set Cache-Control "max-age=2592000"   Header set Cache-Control "max-age=604800"   Header set Cache-Control "max-age=600"   Header unset Cache-Control## ALTERNATE EXPIRES CACHINGExpiresActive OnExpiresDefault A604800ExpiresByType image/x-icon A2592000ExpiresByType application/x-javascript A2592000ExpiresByType text/css A2592000ExpiresByType text/html A300   ExpiresActive Off## META HTTP-EQUIV REPLACEMENTS   Header set imagetoolbar "no"

REWRITES AND REDIRECTS

### REWRITES AND REDIRECTS# REQUEST METHODS: GET,POST,PUT,DELETE,CONNECT,OPTIONS,PATCH,PROPFIND,#                  PROPPATCH,MKCOL,COPY,MOVE,LOCK,UNLOCK## REWRITE DEFAULTSRewriteEngine OnRewriteBase /## REQUIRE SUBDOMAINRewriteCond %{HTTP_HOST} !^$RewriteCond %{HTTP_HOST} !^subdomain\.domain\.tld$ [NC]RewriteRule ^/(.*)$ http://subdomain.domain.tld/$1 [L,R=301]## SEO REWRITESRewriteRule ^(.*)/ve/(.*)$    $1/voluntary-employee/$2 [L,R=301]RewriteRule ^(.*)/hsa/(.*)$     $1/health-saving-account/$2 [L,R=301]## WORDPRESSRewriteCond %{REQUEST_FILENAME} !-f    # Existing FileRewriteCond %{REQUEST_FILENAME} !-d    # Existing DirectoryRewriteRule . /index.php [L]## ALTERNATIVE ANTI-HOTLINKINGRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(subdomain\.)?domain\.tld/.*$ [NC]RewriteRule ^.*.(bmp|tif|gif|jpg|jpeg|jpe|png)$ - [F]## REDIRECT HOTLINKERSRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(subdomain\.)?domain\.tld/.*$ [NC]RewriteRule ^.*\.(bmp|tif|gif|jpg|jpeg|jpe|png)$ http://google.com [R]## DENY REQUEST BASED ON REQUEST METHODRewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|HEAD)$ [NC]RewriteRule ^.*$ - [F]## REDIRECT UPLOADSRewriteCond %{REQUEST_METHOD} ^(PUT|POST)$ [NC]RewriteRule ^(.*)$ /cgi-bin/form-upload-processor.cgi?p=$1 [L,QSA]## REQUIRE SSL EVEN WHEN MOD_SSL IS NOT LOADEDRewriteCond %{HTTPS} !=on [NC]RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]### ALTERNATATIVE TO USING ERRORDOCUMENTRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^.*$ /error.php [L]## SEO REDIRECTSRedirect 301 /2006/oldfile.html http://subdomain.domain.tld/newfile.htmlRedirectMatch 301 /o/(.*)$ http://subdomain.domain.tld/s/dl/$1

AUTHENTICATION AND SECURITY

### AUTHENTICATION AND SECURITY# Require (user|group|valid-user) (username|groupname)## BASIC PASSWORD PROTECTIONAuthType basicAuthName "prompt"AuthUserFile /.htpasswdAuthGroupFile /dev/nullRequire valid-user## ALLOW FROM IP OR VALID PASSWORDRequire valid-userAllow from 192.168.1.23Satisfy Any## PROTECT FILES  Order Allow,Deny  Deny from all## PREVENT HOTLINKINGSetEnvIfNoCase Referer "^http://subdomain.domain.tld/" goodSetEnvIfNoCase Referer "^$" good   Order Deny,Allow   Deny from all   Allow from env=good   ErrorDocument 403 http://www.google.com/intl/en_ALL/images/logo.gif   ErrorDocument 403 /images/you_bad_hotlinker.gif## LIMIT UPLOAD FILE SIZE TO PROTECT AGAINST DOS ATTACK in bytes, 0-2147483647(2GB)LimitRequestBody 10240000

SSL SECURITY

### SSL SECURITY#-> https://www.askapache.com/htaccess/ssl-example-usage-in-htaccess/## MOST SECURE WAY TO REQUIRE SSL#-> https://www.askapache.com/htaccess/apache-ssl-in-htaccess-examples/SSLOptions +StrictRequireSSLRequireSSLSSLRequire %{HTTP_HOST} eq "domain.tld"ErrorDocument 403 https://domain.tld

SITE UNDER CONSTRUCTION

### SITE UNDER CONSTRUCTION# Heres some awesome htaccess to use when you are developing a site## COMBINED DEVELOPER HTACCESS CODE-USE THIS   Header set Cache-Control "max-age=5"AuthType basicAuthName "Ooops! Temporarily Under Construction..."AuthUserFile /.htpasswdAuthGroupFile /dev/nullRequire valid-user           # password prompt for everyone elseOrder Deny,AllowDeny from allAllow from 192.168.64.5      # Your, the developers IP addressAllow from w3.org            # css/xhtml check jigsaw.w3.org/css-validator/Allow from googlebot.com     # Allows google to crawl your pagesSatisfy Any                  # no password required if host/ip is Allowed## DONT HAVE TO EMPTY CACHE OR RELOAD TO SEE CHANGESExpiresDefault A5 #If using mod_expires   Header set Cache-Control "max-age=5"## ALLOW ACCESS WITH PASSWORD OR NO PASSWORD FOR SPECIFIC IP/HOSTSAuthType basicAuthName "Ooops! Temporarily Under Construction..."AuthUserFile /.htpasswdAuthGroupFile /dev/nullRequire valid-user           # password prompt for everyone elseOrder Deny,AllowDeny from allAllow from 192.168.64.5      # Your, the developers IP addressAllow from w3.org            # css/xhtml check jigsaw.w3.org/css-validator/Allow from googlebot.com     # Allows google to crawl your pagesSatisfy Any                  # no password required if host/ip is Allowed

Check out the trends on Google forAskApache, Htaccess, Mod_Rewrite, and HTTPD.

HtaccessAllowAuthUserFileDenyHtaccessRedirectRewriteCondRewriteEngineRewriteRule

 

 

Comments

 

 

Information is freedom. Freedom is non-negotiable. Feel free to modify, copy, republish, sell, or use anything on this site at any time

Online Tools

Popular Articles
Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two.
--Richard M. Stallman


[8]ページ先頭

©2009-2025 Movatter.jp