Task 25 : WordPress Key Files for SEO Speed Security – .htaccess- WP Spartans 300
By : Farooq Shah
Publish Date : December 7, 2018

.htaccess file is very important for WordPress SEO, Speed and Security. It’s all about Apache Web Server Configration. We can also use it to redirect pages, domains and sub directories. Let’s explore it.

In Task # 25 of our three months absolutely free wordpress training under WordPress Spartans Mission 2019, we discussed the importance, creation and editing of .htaccess file. The ht is for Hyper text. We can upload it to root directory or to any directory (such as wp-content of WordPress Themes).

We also discussed how we can stop bots browsing our directories. How to stop bots from hot linking or sql injections etc. We can also ban certain IPs (sort of blacklisting IPs that try to sniff our content). .htaccess is also used for forced downloads etc.

Use this code for Hot Linking Precaution:

## DISABLE HOTLINKING
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https://(www.)?your-website-url.com/.*$ [NC]
RewriteRule .(mp3|jpg|wav)$ – [F]

A great number of Cache plugins such as W3 Total cache add new entries to this file for caching system, browser and header expiry etc.

#Redirect Old Page/ Post to New Post

RewriteEngine On
Redirect 301 /old page or post title here/(one space) http:// or https://yourwebsite.com/new page or post title/

# To redirect whole site (create .htaccess in the root of old site and put this code in it.

Redirect 301 / http:// or https://www.new website url.com/

# To redirect from main directory to sub directory

Redirect /index.html or php (whatever the extension is) /sub directory name here/

#To avoid 404 error

ErrorDocument 404 http:// or https://www.website home page.com/

#Loading sub directory from main root

RewriteEngine on
RewriteRule ^$ /any sub directory name/ [L]

#If someone searches a page on site that doesn’t exist, you can redirect as udner.

Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

## آئی پی وغیرہ کو اجازت دیں یا روک دیں ##

order deny,allow
deny from all
allow from 000.100.1.1
allow from 192.000.1.2

#WPSpartans300 is a mission. WordPress Developers from all over the world have started taking interest in this initiative. Therefore, I’m putting all my energy to make this journey wonderful and full of success.

Link to Access Top WP Developers Mission 2019:
http://bit.ly/2Pgia38

Or, simply visit https://www.freelancepakistan.com and click on 300 Spartan Page.

Through this three months Free WordPress Training (Absolutely FREE), we will learn how to create responsive WordPress Themes and Plugins. We’ll be in a position to sell our assets via Themeforest (Envato) and other platforms. Get ready to conquer that front.

Let me tell you that without passion and commitment, you won’t be able to be a Rockstar WordPress Developer. It does take a lot of hard work ; however, the end result is awesome.

I will guide you step by step so that you could get results from your WordPress Training Mission. Get ready to excel as a professional developer. It’d be fun and exciting adventure.