Jump to content
cosminkent

Htaccess code

Recommended Posts

Posted

http-web-800x525.jpg

Create Custom Error Pages


ErrorDocument 400 / error/400.html
ErrorDocument 401 / error/401.html
ErrorDocument 403 / error/403.html
ErrorDocument 404 / error/404.html
ErrorDocument 500 / error/500.html

Force download of specific types of file


<Files *.mp3>
ForceType application / octet-stream
September Header Content-Disposition attachment
</ Files>
<Files *.xls>
ForceType application / octet-stream
September Header Content-Disposition attachment
</ Files>

Prevent Hotlinking


RewriteEngine On
# Changed? Mysite.com / with the url of our site
RewriteCond% {HTTP_REFERER}! ^ Http:// (. +.)? Mysite.com / [NC]
RewriteCond% {HTTP_REFERER}! ^ $
# Changed / images / nohotlink.jpg with an image that indicates that we do not tolerate the hotlinks
$ / Images / nohotlink.jpg [L] RewriteRule * (png jpe g |? Gif | | bmp)..

Using the cache to increase the speed of our site


# 1 Year
<FilesMatch ".(ico|pdf|flv)$">
September Header Cache-Control "max-age = 29030400, public"
</ FilesMatch>
# 1 Week
<FilesMatch ".(jpg|jpeg|png|gif|swf)$">
September Header Cache-Control "max-age = 604800, public"
</ FilesMatch>
# 2 Days
<FilesMatch ".(xml|txt|css|js)$">
September Header Cache-Control "max-age = 172800, proxy-revalidate"
</ FilesMatch>
# 1 Minutes
<FilesMatch ".(html|htm|php)$">
September Header Cache-Control "max-age = 60, private, proxy-revalidate"
</ FilesMatch>

Create a blacklist of IP addresses


GET POST <Limit PUT>
order allow, deny
allow from all
deny from 123.123.123.1
deny from 555.555.555.5
deny from 000.000.000.0
</ Limit>

Create a PHP error log


# Prevent display errors to the user
display_startup_errors off php_flag
php_flag display_errors off
html_errors off php_flag
# Log errors in the log
php_flag log_errors on
php_value error_log / logs / php_error.log

Redirect mobile devices


RewriteEngine On
RewriteCond% {REQUEST_URI}! ^ / M /. $
RewriteCond% {HTTP_ACCEPT} "text / vnd.wap.wml | application / vnd.wap.xhtml + xml" [NC, OR]
RewriteCond% {HTTP_USER_AGENT} "acs | alav | alkaline | amoi | audi | aste | avan | benq | bird | blac | blaz | brew | cell | cldc | cmd-" [NC, OR]
RewriteCond% {HTTP_USER_AGENT} "dang | doco | eric | HIPT | inno | ipaq | java | jigs | kddi | keji | leno | lg-c | lg-d | lg-g | lge-" [NC, OR]
RewriteCond% {HTTP_USER_AGENT} "maui | maxo | midp | mits | MMEF | mobi | mot-| moto | MWBP | nec-| newt | noki | OPWV" [NC, OR]
RewriteCond% {HTTP_USER_AGENT} "palm | pana | pant | pdxg | phil | play | pluc | port | prox | qtek | qwap | sage | sams | sany" [NC, OR]
RewriteCond% {HTTP_USER_AGENT} "sch-| sec-| send | seri | sgh-| shar | sie-| siem | smal | smar | sony | sph-| symb | ??t-mo" [NC, OR]
RewriteCond% {HTTP_USER_AGENT} "teli | tim-| tosh | tsm-| UPG1 | UPSI | vk-v | voda | W3C's | wap-| wapa | wapi" [NC, OR]
RewriteCond% {HTTP_USER_AGENT} "wapp | wapr | webc | winw | winw | xda | xda-" [NC, OR]
RewriteCond% {HTTP_USER_AGENT} "UP.Browser | UP.Link | windowssce | iemobile | mini | mmp" [NC, OR]
RewriteCond% {HTTP_USER_AGENT} "symbian | midp | wap | phone | pocket | mobile | pda | psp" [NC]
# ------------- The line below excludes the iPad from the list
RewriteCond% {HTTP_USER_AGENT}! ^. * IPad. * $
# -------------
RewriteCond% {HTTP_USER_AGENT}! Macintosh [NC] # * SEE NOTE BELOW
RewriteRule ^ (. *) $ / M / [L, R = 302]

Support for video in HTML5


RewriteCond% {REQUEST_FILENAME}!-F
RewriteCond% {REQUEST_FILENAME}!-D
RewriteCond% {REQUEST_URI}! = / Favicon.ico
AddType video / ogg. Ogv
AddType video / ogg. Ogg
AddType video/mp4. Mp4
AddType video / webm. Webm
AddType application / x-shockwave-flash swf

301 Redirects


Redirect 301 / d / file.html http://www.domainname.com/r/file.html

To protect a specific file


<Files Wp-config.php>
order allow, deny
deny from all
</ Files>

Password protect a directory


# Password protecting a file
secure.php=""> <Files
AuthType Basic
AuthName "Prompt"
AuthUserFile / home / path / htpasswd
Require valid-user
</ Files>

# Password-protect a directory
reside
AuthType basic
AuthName "This directory is protected"
AuthUserFile / home / path / htpasswd
AuthGroupFile / dev / null
Require valid-user

Remover www URLs of your site


# Remove www from URL
RewriteEngine On
RewriteCond% {HTTP_HOST} ^ www \. Domain \. Com $ [NC]
RewriteRule ^ (. *) $ Http://domain.com/ $ 1 [L, R = 301]

Source: uc0

Posted

Foarte bine facut articolul.

Totusi as avea ceva de subliniat pt cei care intentioneaza sa-l foloseasca:

htaccess este "greoi", de aceea daca sunteti pe shared hosting (si aveti acces doar la htaccess) sa va ganditi ca unele actiuni pot fi obtinute cu php care de cele mai multe ori este mai rapid decat htaccess.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...