This an awesome content about htaccess! We share some important .htaccess code on the article. So What is a .htaccess code/file? That’s may be on your mind.

What htaccess do?

The .htaccess file is the most important file for WordPress/PHP Sites. You can say, it’s the blood of your website. If you do some mistakes or take the wrong blood your website. Your website will stop working, Maybe gets some errors on the visit. It’s maybe possible, That your website not opening. I just call it Blood, So please don’t take it wrong.

What can do access?

  • Control your website file access to the users,
  • help to set up permalink
  • htaccess can give you password protect on pages
  • Its help you to make a firewall on your website
  • You can block specific locations traffics on your website.
  • .htaccess can set redirect_url (Note: It’s possible with HTML/javascript)

That was the basics uses of htaccess file but primarily we used for this kind of works. So we just tell you some basic, it will help you do understand, Why we used the htaccess file on our websites.

Can’t see .htaccess in CPanel

Their lots of people having problem to find out access  file on the cpanel. How can you find your htaccess in your Cpanel? Why You Can’t find .htaccess file on your WordPress site?


You can see the screenshot right side top Settings. Tap on Settings then a popup comes on your screen, mark on Show Hidden Files (dotfiles) field, Then click on Save.

Now all are Done if you followed my instruction properly. Now refresh the page,  you can see the htaccess file. You can find .htaccess file in WordPress websites.

Force www htaccess  code

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule ^(.*)$$1 [L,R=301,NC]

The following code force the user to visit your website www on every time. if you visitor write only domain name without www, When the visitor visit on the link. your website/page automatically added www.

Force without www htaccess  code

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{HTTPS}s ^on(s)|off
RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$
RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L]

The htaccess code forces your traffic visit without www. on your site. If some want to visit www. the traffic can’t visit. If you want without www. the code help with it.

.htaccess force https

RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This code force the traffic to visit with https on all your webpage.

Force Trailing Slash

RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

Following code, if added, Then visitors force to visit with: without the code visitors can visit these type of permalink.

Remove Trailing Slash

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

This snippet will redirect paths ending in slashes to their non-slash-terminated counterparts (except for actual directories), e.g. to This is important for SEO, since it’s recommended to have a canonical URL for every page.

.htaccess 301 redirect

Redirect 301 /oldpage.html

following the code, you can set .htaccess 301 redirects on your website. if you change any link on the site soon as possible add a redirect on the new page. That will help you to drive your traffic from Search engines.

Old domain to new another Redirect

RewriteEngine on
RewriteBase /
RewriteRule (.*)$1 [R=301,L]

Are you changing your domain name? You need to setup perfect redirection? Of course, you need!

If you don’t give redirect the old domain to the new domain name? You maybe lose your traffic as well as revenue & sales. So make sure you gave redirect your old domain to the new domain. This Redirect system is easy. Just make .htaccess file on the server. There hosted your old domain name. Now copy the upper code & paste it on the old domain htaccess file. If some one visited > Traffic automatically So don’t need to set 301/302 redirect on the old domain.

Block traffic Via .htaccess

Deny from all

Simply copy the code & paste it on the .htaccess file now save it. All traffic is blocked. Nobody can visit your website.

Block all IP without your via .htaccess

Order deny,allow
Deny from all
Allow from

This code means only your IP address can visit the website & without your IP address all are blocked. it’s maybe to help you. When you don’t wanna share something from others. You can find your IP address: whoer visit the website, copy your IP & just replace the IP

Block Spammers IP Via .htaccess

Order deny,allow
Deny from
Deny from

Copy the htaccess code and paste it on the htaccess file. The code helps you to block spammers IP address. you can block spammers following the htaccess code.

Remember: All User able to visit, If you put any spammers IP, Next time spammer can’t visit your site. So make sure you have given the correct IP address.

What is image HotLinking?

Image hotlinking mean? if some one copies your image link & load the image from other websites. That means it loaded from your servers. So taking your bandwidth from the server. So it maybe give you bad effects, if don’t have good quality hosting. Hotlinking does not give bad effects on SEO but takes your bandwidth only. If you wish to stop image hotlinking on your website. The following code maybe helpful for you & hosting as well.

Disable Image Hotlinking using .htaccess

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(.+\.)? [NC] RewriteRule \.(jpe?g|png|gif|bmp)$ - [NC,F,L]

How to Display image hotlink protection? just simply put the code. Now nobody can copy your images. There most of the hosting companies giving hotlink protection. your hosting provider also can enable the protection. Cloudflare also gives free hotlink protection, So you can use any of the methods.

Check our others article: 10 Best Adsense Alternative: Choose Best Adnetwork for Your Website

Propeller Ads Review: A Highly Effective Ad network