Useful .htaccess Tips & Tricks for WordPress

Useful .htaccess Tips & Tricks for WordPress

Useful .htaccess Tips & Tricks for WordPress

The .htaccess is the configuration file of the Apache web server, which we can work to tailor the server and WordPress accordance with our needs.

Here are some useful examples of settings that can be applied in .htaccess in wordpress .

1 Remove the / category / from url

The WordPress category permalinks, by default, as follows:

To remove the / category / from WordPress URL, initially cared to keep a backup of .htaccess file. Then did .htaccess file and in it, paste the following:

RewriteRule ^ category /(.+)$$1 [R = 301, L]

After you save, the pages of categories will appear as follows:

2 Use the Browser Cache

You can make your site the more quickly and reduce the loading time, using the Browser Cache. The following code does direct intervention in loading speed, but improves the display speed of the page when a user visits again. That is, if the user has visited a page of your site in the past, the content will be loaded from the local cache of the browser of the visitor and thus would take less time to load the browser the website.
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 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 2 days”

3 disable hotlinking

Several times, administrators sites use images or other files from your own site, “pulling” them from the server you. This has the effect seen in the pages of extra traffic to your site. In this way, not only lose traffic from your pages, but you ‘push’ and movement. To ban someone be able to use the technique hotlinking and thus loads the site’s files through your site, use the code below:

RewriteEngine On
#Replace? Mysite \ .com / with your blog url
RewriteCond% {HTTP_REFERER}! ^ Http: // (. + \.)? Mysite \ .com / [NC]
RewriteCond% {HTTP_REFERER}! ^ $
#Replace /images/nohotlink.jpg With your «do not hotlink» image url
RewriteRule. * \. (Jpe? G | gif | bmp | png) $ /images/nohotlink.jpg [L]

4 Block an IP

Usually block IPs of Spammers that add comments to our page with Links! You can block one IP, to disallow access this user to your site with the code below:

order allow, deny
deny from
allow from all

You need to be very careful with the changes you make in .htaccess file, as changes may not work directly or create a problem, without want.

For this reason, it is important to always keep a backup of the old version of your blog and web site. Good Luck!

We will be happy to hear your thoughts

Leave a reply