We are aware of a potentially service impacting issue. Learn more

htaccess و کاربرد آن Print


 

موارد کاربرد فایل .htaccess

۱٫     Set TimeZoneتنظیم زمان سایت با کد زیر:

1

SetEnv TZ Asia/Tehran

۲٫      ۳۰۱ permanent Redirectاستفاده از  ۳۰۱ Permanent Redirects برای استفاده در موتور های جستجو

1

Redirect 301 http://www.domain.com/home  http://www.domain.com/

۳٫     اضافه کردن mime-typeحذف پرسش سرور پیرامون اینکه فایل را باز می نمایید و یا دانلود می کنید. براحتی فایل مورد نظر را download  نمایید.

1

AddType application/octet-stream .pdf

1

AddType application/octet-stream .zip

 

1

AddType application/octet-stream .mov

۴٫     حذف wwwارجاع تمام درخواست ها برای باز شدن سایت با www  به URL  سایت که به بهینه سازی برای موتورهای جستجوگر کمک می نماید.

1

RewriteEngine On

1

RewriteBase /

 

1

RewriteCond %{HTTP_HOST} ^www.domain.com [NC]

1

RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

۵٫     Custom Error pageایجاد نمایش خطاهای دلخواه و مسیردهی آن

1

ErrorDocument 401 /error/401.php

1

ErrorDocument 403 /error/403.php

 

1

ErrorDocument 404 /error/404.php

1

ErrorDocument 500 /error/500.php

۶٫     Compress filesبهینه سازی سرعت load  سایت با فشرده سازی فایل ها

1

# compress text, html, javascript, css, xml:

1

AddOutputFilterByType DEFLATE text/plain

 

1

AddOutputFilterByType DEFLATE text/html

1

AddOutputFilterByType DEFLATE text/xml

 

1

AddOutputFilterByType DEFLATE text/css

1

AddOutputFilterByType DEFLATE application/xml

 

1

AddOutputFilterByType DEFLATE application/xhtml+xml

1

AddOutputFilterByType DEFLATE application/rss+xml

 

1

AddOutputFilterByType DEFLATE application/javascript

1

AddOutputFilterByType DEFLATE application/x-javascript

۷٫     Cache files

Cache یکی دیگر از روش های مشهور بهینه سازی load  سایت

1

FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$

1

Header set Cache-Control "max-age=2592000"

 

1

/FilesMatch

۸٫     Disable caching for certain file typeشما می توانید cache  برای نوع فایل دلخواهی غیرفعال نمایید.

1

# explicitly disable caching for scripts and other dynamic files

1

FilesMatch ".(pl|php|cgi|spl|scgi|fcgi)$

 

1

Header unset Cache-Control

1

/FilesMatch

امنیت

۹٫     Hotlinking protection with .htaccessبرای جلوگیری از استفاده تصاویر سایت شما مصرف پهنای باند سایت شما از طریق  کد زیر قادر به جلوگیری خواهید بود:

1

RewriteBase /

1

RewriteCond %{HTTP_REFERER} !^$

 

1

RewriteCond %{HTTP_REFERER} !^http://(www.)?queness.com/.*$ [NC]

1

RewriteRule .(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]

۱۰٫ Prevent hacksبا استفاده از خطوط زیر می توانید از چند روش رایج هک شدن سایت خود جلوگیری نمایید.

1

RewriteEngine On

1

# proc/self/environ? no way!

 

1

RewriteCond %{QUERY_STRING} proc/self/environ [OR]

1

# Block out any script trying to set a mosConfig value through the URL

 

1

RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|%3D) [OR]

1

# Block out any script trying to base64_encode crap to send via URL

 

1

RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]

1

# Block out any script that includes a script tag in URL

 

1

RewriteCond %{QUERY_STRING} (|%3C).*script.*(|%3E) [NC,OR]

1

# Block out any script trying to set a PHP GLOBALS variable via URL

 

1

RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]

1

# Block out any script trying to modify a _REQUEST variable via URL

 

1

RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})

1

# Send all blocked request to homepage with 403 Forbidden error!

 

1

RewriteRule ^(.*)$ index.php [F,L]

 

 

 


Was this answer helpful?

  • 0
« Back