Sharing Information
Sharing Information
Picture of the author
Pankaj PawarinSEO
17th Sept 24.07:00 Min.
https://sharinginfo.in/wordpress/wordpress-htaccess-file-seo-optimized-20.html

WordPress .htaccess file – SEO optimized

WordPress .htaccess file – SEO optimized
Photo by Simon Abrams on Unsplash

In this post I have mention the code for .htaccess file, this will help you to improve your page speed and SEO ranking.

The basic WordPress .htaccess file have basic URL rewriting rules

# 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

Now we will start to optimize your wordpress site

Step 1: leverage browser caching

## EXPIRES CACHING ##
<IfModule mod_expires.c>
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"
</IfModule>
## EXPIRES CACHING ##

Step 2: Compress Your page content

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

Step 3: Compress Your HTML

function sanitize_output($buffer) { $search = array( '/\>[^\S ]+/s', // strip whitespaces after tags, except space '/[^\S ]+\', '<', '\\1' ); $buffer = preg_replace($search, $replace, $buffer); return $buffer;
}
ob_start("sanitize_output");

add this code into your theme index.php file.

this will definitely help you to increase your page speed.

Sharing Info Cookie Consent

Our website uses cookies to improve your browsing experience and relevant content delivery. Before continuing to use our website, you agree & accept of our Cookie Policy & Privacy.