Htaccess Guide: How to Create ( 3 powerful Feature)

Htacess Guide

Today I am going to guide you about the .htaccess file which is a very important file for every website.

I will also share some useful codes which keep your website secure and fast.

(Including lots of real-life examples)

You can set many security settings with the help of .htaccess files like redirection, block bots, spam comment, clear cache and many more.


What is .htaccess?

htaccess file on server

.htaccess is a configuration file which is included in every website.

If your website on WordPress the It is automatically created otherwise

If your website on another platform you will have to create it manually.


How to create a .htaccess file in PHP

#1. Open your server cpanel and log in.

#2. In your Files section, click on File manager icon.

#3. Make sure that Show Hidden Files (dotfiles)” is checked.

#4. Finally .htaccess file found.

Create a txt file and paste recommended code in this file

You can also upload txt file in this root.


How to create a .htaccess file in WordPress

In WordPress .htaccess default included. But sometimes, the .htaccess file is not present in WordPress, then you have to manually create.

If your website of WordPress simply installs the YOAST plugin. Because YOAST plugin creates .htaccess file automatically no need to open CPanel.

#1. Open your WordPress website dashboard.

#2. Go to SEO and click on Tools setting

#3. Here you see File Editor click on this.

#4. you Get .htaccess file

Another way to create a .htaccess file in WordPress

This process is so simple to create a .htaccess file.

Simply open cPanel and add a new file and rename it as .htaccess.

And paste some lines of code given below.

 This is default code for your WordPress .htaccess file:

# BEGIN WordPress
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule. /index.php [L]
# END WordPress


How to create a .htaccess file in WordPress

This is a very important file on the website. I recommend you to check your server that .htaccess file is there or not.

There are many features of .htaccess. Here I mention top 3 feature.

  • Clean your website cache and increase your website speed.
  • block unwanted spam IP addresses. 


1. Clean your website cache and increase your website speed.

.htaccess clear Leverage Browser Caching. You can check your website Leverage Browser Cache from 
Leverage Browser Caching slow your website. so, I recommend you to add Leverage Code in your .htaccess file.
Add the following code in your .htaccess file. And check your website speed.


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 2 days”



2. Blocking spam comment

This is a very big problem with all the website. if you use WordPress then Akismet plugin is the best solution to this problem

Its block all spam comment and scan your website.

If your website not on WordPress then doesn’t worry. Simply add this code in your .htaccess

Its automatically block spammer IP address.

Copy code and add in .htaccess file

order allow, deny
deny from
allow from all

If more than one spammer sends spam comment in your website then add his IP address like this. Means you can always enter more IP’s.

You can get the IP from Comment admin page option or your Gmail.

deny from

<Limit GET POST>
order allow, deny
deny from 88.146.819.123
deny from 122.148.319.127
deny from
deny from
allow from all


Now It’s Your Turn

So, these are the best uses of a .htaccess file.

Now I’d like to hear from you:

If you like this information then share this post in your social media and bookmark to my website in your browser.

If any problem and confusion, let me know by leaving a comment.