2011-07-17 12 views
27

क्या कोई मुझे एक विशिष्ट वेबसाइट के लिए संपीड़न, ब्राउज़र कैशिंग, प्रॉक्सी कैशिंग इत्यादि को अनुकूलित करने वाला एक अनुकूलित। Htaccess कॉन्फ़िगरेशन प्रदान कर सकता है?htaccess द्वारा कैशिंग और gzip संपीड़न

मेरे आगंतुकों के अलावा, मैं Google पेजस्पेड को खुश करने की भी कोशिश कर रहा हूं। मैं .htaccess के माध्यम से कैशिंग और gzip संपीड़न का उपयोग करना चाहता हूं कृपया मुझे इसके कोड के साथ मदद करें!

मैं लंबे समय

मैं 2 दिन

मैं 2 दिन

और मैं अपने html,txt,css,js,php फ़ाइलों को संपीड़ित करना चाहते हैं के लिए html फ़ाइलों को कैश करने के लिए xml,txt फ़ाइलों को कैश करने के लिए icon,pdf,flv,jpg,png,gif,js,css,swf फ़ाइलों को कैश करना चाहते हैं क्योंकि उनके पास बड़ी फ़ाइल आकार है।

क्या .htaccess का उपयोग कर छवियों को gzip करने का कोई तरीका है?

+1

'gzip' वाली छवियों को संपीड़ित करना बहुत रुचि नहीं है, क्योंकि जीआईएफ, जेपीईजी या पीएनजी पहले ही संपीड़ित प्रारूप हैं। बैंडविड्थ में किसी भी लाभ के बिना, उन्हें संपीड़ित करना आपके सर्वर पर सीपीयू रिसोर्स का नुकसान होगा। –

+0

@ हकर: इस दोस्त को छोड़कर मेरे पास कोई सही जवाब नहीं है! –

+1

क्या आप @ हामिद सेयदेदी हैं? यदि आप हैं, तो यह उपयोगकर्ता खाता और [आपका दूसरा] (http://stackoverflow.com/users/784971/hamid-seyyedi) को एक खाते में विलय करने की आवश्यकता है। आपको दो अलग-अलग खातों की अनुमति नहीं है। –

उत्तर

44
# 480 weeks 
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> 
Header set Cache-Control "max-age=290304000, public" 
</FilesMatch> 

# 2 DAYS 
<FilesMatch "\.(xml|txt)$"> 
Header set Cache-Control "max-age=172800, public, must-revalidate" 
</FilesMatch> 

# 2 HOURS 
<FilesMatch "\.(html|htm)$"> 
Header set Cache-Control "max-age=7200, must-revalidate" 
</FilesMatch> 

<ifModule mod_gzip.c> 
    mod_gzip_on Yes 
    mod_gzip_dechunk Yes 
    mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ 
    mod_gzip_item_include handler ^cgi-script$ 
    mod_gzip_item_include mime ^text/.* 
    mod_gzip_item_include mime ^application/x-javascript.* 
    mod_gzip_item_exclude mime ^image/.* 
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* 
</ifModule> 
+0

@ हकर: इस दोस्त को छोड़कर मेरे पास कोई सही जवाब नहीं है! अपनी आंखें खोलो! –

+2

हिस्सा मेरे लिए काम नहीं किया। जब मैंने अपनी साइट पर कोशिश की तो मुझे त्रुटि 500 ​​मिली! हालांकि नीचे दिए गए उत्तर में AddOutputFilterByType विधि पूरी तरह से काम करता है। इन दो तरीकों के बीच क्या अंतर है? – maxxon15

+1

अपाचे 1.3 [mod_gzip] का उपयोग करता है (http://sourceforge.net/projects/mod-gzip/) जबकि अपाचे 2.x [mod_deflate] का उपयोग करता है (http://httpd.apache.org/docs/2.0/mod/mod_deflate .html)। तो कृपया अपने अपाचे संस्करण की जांच करें, यह महत्वपूर्ण है! – Andron

16

इस प्रयास करें:

<IfModule mod_deflate.c> 
    #The following line is enough for .js and .css 
    AddOutputFilter DEFLATE js css 
    AddOutputFilterByType DEFLATE text/plain text/xml application/xhtml+xml text/css application/xml application/rss+xml application/atom_xml application/x-javascript application/x-httpd-php application/x-httpd-fastphp text/html 

    #The following lines are to avoid bugs with some browsers 
    BrowserMatch ^Mozilla/4 gzip-only-text/html 
    BrowserMatch ^Mozilla/4\.0[678] no-gzip 
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
</IfModule> 

# BEGIN EXPIRES 
<IfModule mod_expires.c> 
    ExpiresActive On 
    ExpiresDefault "access plus 10 days" 
    ExpiresByType text/css "access plus 1 week" 
    ExpiresByType text/plain "access plus 1 month" 
    ExpiresByType image/gif "access plus 1 month" 
    ExpiresByType image/png "access plus 1 month" 
    ExpiresByType image/jpeg "access plus 1 month" 
    ExpiresByType application/x-javascript "access plus 1 month" 
    ExpiresByType application/javascript "access plus 1 week" 
    ExpiresByType application/x-icon "access plus 1 year" 
</IfModule> 
# END EXPIRES 

<IfModule mod_headers.c> 
    <FilesMatch "\.(js|css|xml|gz)$"> 
     Header append Vary Accept-Encoding 
    </FilesMatch> 
    <FilesMatch "\.(ico|jpe?g|png|gif|swf)$"> 
     Header set Cache-Control "public" 
    </FilesMatch> 
    <FilesMatch "\.(css)$"> 
     Header set Cache-Control "public" 
    </FilesMatch> 
    <FilesMatch "\.(js)$"> 
     Header set Cache-Control "private" 
    </FilesMatch> 
    <FilesMatch "\.(x?html?|php)$"> 
     Header set Cache-Control "private, must-revalidate" 
    </FilesMatch> 
</IfModule> 
+2

अपाचे 2.4 में ऐसे दोनों मॉड्यूल को 'deflating' का उपयोग करने के लिए सक्षम होना चाहिए: mod_deflate.so और mod_filter.so – Andron

2

आप के रूप में कोड का उपयोग कर सकते हैं: -

<Files *> 
    #Compress 

    SetOutputFilter GZIP 

    #Caching 

    Header set Cache-Control "max-age=3600, public" 


</Files> 
1

आप अपनी .htacces फ़ाइल में निम्नलिखित नियम का उपयोग करना चाहिए मुझ पर भरोसा यह कम से कम 10 अंक में वृद्धि होगी यदि आप पहले से ही इसका उपयोग नहीं कर रहे हैं।

 

mod_gzip_on Yes 
mod_gzip_dechunk Yes 
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ 
mod_gzip_item_include handler ^cgi-script$ 
mod_gzip_item_include mime ^text/.* 
mod_gzip_item_include mime ^application/x-javascript.* 
mod_gzip_item_exclude mime ^image/.* 
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* 


AddOutputFilterByType DEFLATE application/javascript 
AddOutputFilterByType DEFLATE application/rss+xml 
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject 
AddOutputFilterByType DEFLATE application/x-font 
AddOutputFilterByType DEFLATE application/x-font-opentype 
AddOutputFilterByType DEFLATE application/x-font-otf 
AddOutputFilterByType DEFLATE application/x-font-truetype 
AddOutputFilterByType DEFLATE application/x-font-ttf 
AddOutputFilterByType DEFLATE application/x-javascript 
AddOutputFilterByType DEFLATE application/xhtml+xml 
AddOutputFilterByType DEFLATE application/xml 
AddOutputFilterByType DEFLATE font/opentype 
AddOutputFilterByType DEFLATE font/otf 
AddOutputFilterByType DEFLATE font/ttf 
AddOutputFilterByType DEFLATE image/svg+xml 
AddOutputFilterByType DEFLATE image/x-icon 
AddOutputFilterByType DEFLATE text/css 
AddOutputFilterByType DEFLATE text/html 
AddOutputFilterByType DEFLATE text/javascript 
AddOutputFilterByType DEFLATE text/plain 
AddOutputFilterByType DEFLATE text/xml 
BrowserMatch ^Mozilla/4 gzip-only-text/html 
BrowserMatch ^Mozilla/4\.0[678] no-gzip 
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
Header append Vary User-Agent 


ExpiresActive On 
ExpiresByType image/jpg "access 1 year" 
ExpiresByType image/jpeg "access 1 year" 
ExpiresByType image/gif "access 1 year" 
ExpiresByType image/png "access 1 year" 
ExpiresByType text/css "access 1 month" 
ExpiresByType text/html "access 1 month" 
ExpiresByType application/pdf "access 1 month" 
ExpiresByType text/x-javascript "access 1 month" 
ExpiresByType application/x-shockwave-flash "access 1 month" 
ExpiresByType image/x-icon "access 1 year" 
ExpiresDefault "access 1 month" 

1

.htaccess

ज्यादातर लोगों में यह पढ़ने के लिए के माध्यम से संपीड़न सक्षम करें, संपीड़न उनके वेब होस्ट/सर्वर पर किसी फ़ाइल कहा जाता .htaccess करने के लिए कुछ कोड जोड़ने से सक्षम है। इसका मतलब है कि आपके वेबहोस्ट पर फ़ाइल प्रबंधक (या जहां भी आप फ़ाइलों को जोड़ने या अपलोड करने के लिए जाते हैं) पर जा रहे हैं।

.htaccess फ़ाइल आपकी साइट के लिए कई महत्वपूर्ण चीजें नियंत्रित करती है। यदि आप .htaccess फ़ाइल से परिचित नहीं हैं, तो कृपया इसे बदलने से पहले कुछ जानकारी प्राप्त करने के लिए .htaccess आलेख के साथ काम करना पढ़ें।

नीचे कोड अपनी .htaccess फाइल में जोड़ा जाना चाहिए ...

<ifModule mod_gzip.c> 
mod_gzip_on Yes 
mod_gzip_dechunk Yes 
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ 
mod_gzip_item_include handler ^cgi-script$ 
mod_gzip_item_include mime ^text/.* 
mod_gzip_item_include mime ^application/x-javascript.* 
mod_gzip_item_exclude mime ^image/.* 
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* 
</ifModule> 

सहेजें .htaccess फाइल और फिर आपके वेबपृष्ठ को ताज़ा करें।

यह देखने के लिए जांचें कि आपका संपीड़न Gzip compression tool का उपयोग कर काम कर रहा है या नहीं।

संबंधित मुद्दे