This an Awesome Content for You! We are gives you .htaccess files on the article. So What is an .htaccess code/file? That may me on your mind.

What htaccess do?

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

What can do htaccess?

  • Control your website file access to the users,
  • help to setup permalink
  • htaccess can give you password protect on pages
  • Its help you to make 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 kinds of works. So we just tell you some basic, it will help you do understand, Why we used the htaccess  file in our websites.

Can’t see .htaccess in cpanel

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

htaccess

You can see the screenshot right side top Settings. Tap on Settings then an 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 ^(.*)$ http://www.example.com/$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 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 force your traffic visit without www. on you site. If some want to visit with www. the traffic can’t visit. If you want without www. the code help on 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: domain.com/page/ without the code visitors can visit domain.com/page this types 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. http://www.example.com/blog/ to http://www.example.com/blog. This is important for SEO, since it’s recommended to have a canonical URL for every page.

.htaccess 301 redirect

Redirect 301 /oldpage.html http://www.example.com/newpage.html

following the code you can set .htaccess 301 redirect on your website. if you changes any link on the site soon as possible add 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 (.*) http://www.newdomain.com/$1 [R=301,L]

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

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

Block traffic Via .htaccess

Deny from all

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

Block all IP without your via .htaccess

Order deny,allow
Deny from all
Allow from xxx.xxx.xxx.xxx

This code means only your ip address can visit the website & without your ip address all are blocked. it’s maybe 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 xxx.xxx.xxx.xxx

Block Spammers IP Via .htaccess

Order deny,allow
Deny from xxx.xxx.xxx.xxx
Deny from xxx.xxx.xxx.xxy

Copy the htaccess code and paste it on htaccess file. The code help 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 given correct ip address.

What is image HotLinking?

Image hotlinking mean? if some one copy your image link & load the image from others website. That mean it loaded from your servers. So taking yours bandwidth from server. So its maybe give you bad effects, if don’t have good quality hosting. Hotinking not give bad effects in 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?://(.+\.)?example.com [NC] RewriteRule \.(jpe?g|png|gif|bmp)$ - [NC,F,L]

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

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

Propeller Ads Review: A Highly Effective Ad network