我应该删除或添加.htaccess文件中的内容吗?

时间:2017-04-19 12:13:29

标签: wordpress .htaccess

htaccess文件..这样可以,或者我有任何错误吗?

这些代码中的一些由wordpress插件生成,我添加了一些我从一些博客中找到的行。所以你怎么看?我应该删除或添加一些东西吗?

        # BEGIN Far Future Expiration Plugin
        <IfModule mod_expires.c>
        ExpiresActive on
        <FilesMatch "\.(gif|jpeg|jpg|png|ico|js|css|swf)$">
        ExpiresDefault "access plus 168 hours"
        </FilesMatch>
        </IfModule>
        # END Far Future Expiration Plugin

        #Expires headers configuration added by Speed of Light plugin
        <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault A2592000
        ExpiresByType application/javascript "access plus 7 days"
        ExpiresByType text/javascript "access plus 7 days"
        ExpiresByType text/css "access plus 7 days"
        ExpiresByType image/jpeg "access plus 7 days"
        ExpiresByType image/png "access plus 7 days"
        ExpiresByType image/gif "access plus 7 days"
        ExpiresByType image/ico "access plus 7 days"
        ExpiresByType image/x-icon "access plus 7 days"
        ExpiresByType image/svg+xml "access plus 7 days"
        ExpiresByType image/bmp "access plus 7 days"
        ExpiresByType font/truetype "access plus 7 days"
        ExpiresByType font/opentype  "access plus 7 days"
        ExpiresByType application/x-font-woff "access plus 7 days"
        ExpiresByType application/vnd.ms-fontobject "access plus 7 days"
        </IfModule>
        #End of expires headers configuration

        # BEGIN WordPress
        <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
        </IfModule>

        # END WordPress

        <IfModule mod_deflate.c>
        # Compress HTML, CSS, JavaScript, Text, XML and fonts
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/x-javascript
        AddType x-font/otf .otf
        AddType x-font/ttf .ttf
        AddType x-font/eot .eot
        AddType x-font/woff .woff
        AddType image/x-icon .ico
        AddType image/png .png
        AddType text/css .css
        AddType image/jpg .jpg

        # Remove browser bugs (only needed for really old browsers)
        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
        </IfModule>

        # BEGIN WordPress
        <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
        </IfModule>

        # END WordPress

        <IfModule mod_deflate.c>
        # Compress HTML, CSS, JavaScript, Text, XML and fonts
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/x-javascript
        AddType x-font/otf .otf
        AddType x-font/ttf .ttf
        AddType x-font/eot .eot
        AddType x-font/woff .woff
        AddType image/x-icon .ico
        AddType image/png .png
        AddType text/css .css
        AddType image/jpg .jpg

        # Remove browser bugs (only needed for really old browsers)
        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
        </IfModule>

        <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>

        # BEGIN WP Performance Score Booster Settings
        # END WP Performance Score Booster Settings

PS我的最后一个ifModule是否具有较低的i而不是大写I是否重要?

2 个答案:

答案 0 :(得分:0)

以下代码默认为htaccess for rewrite engine on ..

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

我已经看到你的htaccess剩余代码用于改善使用htaccess的性能。当你安装一些像wp-security,wordfance等插件时,在htaccess中添加额外的代码..

答案 1 :(得分:0)

你喜欢2次相同的代码

    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddType x-font/otf .otf
    AddType x-font/ttf .ttf
    AddType x-font/eot .eot
    AddType x-font/woff .woff
    AddType image/x-icon .ico
    AddType image/png .png
    AddType text/css .css
    AddType image/jpg .jpg

尝试备份您的文件.htaccess并删除其中一个。

如果不工作则删除另一个