banner



How To Add Code To .htaccess File

Edit WordPress .htaccess File

The .htaccess file is a configuration file that is located in the root of your WordPress installation. This file can be used to override the general settings of your WordPress installation, .htaccess is an abbreviation of term 'Hypertext Access'. There is a period that precedes the file name '.htaccess' which simply ways it is a hidden file. You lot are non probable to see .htaccess file on your browser.

You tin can implement a number of changes on your site by editing. .htaccess. The changes include; redirecting URLs, protecting your images from hotlinking, preventing access to site binder or blocking IPs from accessing your site.

In this postal service, we will expect at how to edit .htaccess and how you lot can use .htaccess to override the other settings on your site.

1 Precautions of Editing .htaccess

When yous are editing .htaccess it's of import to exercise maximum circumspection since errors on .htaccess file will cause your site to vanquish. Locating the .htaccess can also be difficult; here are two precautions to guide y'all when you edit .htaccess:

  • Show Hidden Files – when editing .htaccess in the cPanel, you need to bank check the setting 'Show Hidden Files' for you to view and edit .htaccess. In some web hosting you may be required to alter the permission settings to view the .htaccess file.
  • Backup .htaccess – creating a fill-in copy of the .htaccess file is the most important precaution when editing .htaccess file. This backup copy is used to restore back the site to the original status if something goes wrong when editing .htaccess file.

two How to Edit WordPress .htaccess File

WordPress .htaccess file comprises of directives to your server on how to handle various scenarios. These instructions to the server will have a direct touch on your website.

Information technology is, therefore, necessary yous exercise maximum caution when editing .htaccess to prevent crushing your website. The near mutual instructions you will find in a WordPress .htaccess file are redirects and rewriting of URLs. WordPress has a set of instructions on the .htaccess that control how WordPress sites behave. The basic .htaccess in WordPress contain the following content:

Basic WordPress .htaccess

# Brainstorm WordPressRewriteEngine On
RewriteBase /
RewriteRule ^alphabetize.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]# Stop WordPress

3 Understanding Contents of .htaccess

WordPress basic .htaccess contains a number of lines of lawmaking and y'all tin also add together your ain instructions to manipulate Apache server in your hosting. Before yous can write any rules, information technology is of import yous begin by understanding what these lines of code mean. There are instructions and comments in the .htaccess; the latter helps yous empathize instructions to the server. The other lines of lawmaking are instructions to the server on how to carry out certain functions.

four Writing .htaccess Comments

When you look at .htaccess file you are likely to run into lines that are preceded by a hash sign. These lines are referred as comments and as stated in a higher place they assist you sympathise the code.

Writing comments in .htaccess requires yous to add a hash sign (#) before yous write the comment. Here are 2 examples of .htaccess comments:

# Redirects 301

# 404 Errors Pages

v How to create .htaccess File in WordPress

You can create .htaccess past simply opening a text editor and calculation the content of .htaccess and saving the file as .htaccess. If you don't accept a .htaccess in your site, you tin create one and upload it to your server through the cPanel or FTP client.

6 Means of Editing .htaccess File

There are different ways y'all can use to edit .htaccess file that include:

  • cPanel .htaccess edit
  • WordPress Dashboard .htaccess edit
  • FTP Customer .htaccess

The quickest way to edit .htaccess file is through the cPanel, this article will explain each of these means of editing .htaccess.

7 How to Edit .htaccess File from cPanel

It is possible to easily edit .htaccess from your hosting cPanel. Earlier you tin edit the .htaccess in your hosting cPanel, you need to locate it first. Here are the steps you should accept:

  • Log into hosting cPanel
  • Locate the File Manager or Files Icon as shown below:

Edit .htaccess File Manager

  • Click the selection to view the Document Root for the domain you want to edit .htaccess
  • Choose the option to shown hidden files.

WordPress Root Folder

  • When you open the File Managing director, locate the .htaccess file and correct click on it to edit.

.htaccess  file in Root Folder

  • Copy the contents of the .htaccess before you lot begin editing and save a backup copy.
  • Open the .htaccess file after creating a backup and add together your instructions. Save the file and refresh your site to check for the changes.

8 How to Edit .htaccess file from WordPress Dashboard

Editing .htaccess from the dashboard is the best solution if you lot do not have FTP access or cPanel logins. There is no inbuilt WordPress characteristic that enables you to edit .htaccess from the dashboard. Nevertheless, there are plugins that are used for editing WordPress .htaccess from the dashboard.

WP .htaccess Editor is the best plugin for editing .htaccess from WordPress dashboard. This plugin is awesome since information technology besides has a characteristic to allow y'all to restore a backup only increment anything goes wrong.

WP .Htaccess Editor Plugin is free and can be downloaded from WordPress repository. To edit .htaccess from WordPress dashboard, install this plugin and activate it.

.htaccess File ContentAnother plugin that has .htaccess edit functionality is Rank Math SEO. Rank Math SEO is the i of the most popular WordPress SEO plugin, if you have it installed go to General Setting on the master menu and then click `Edit .htaccess`.

On the .htaccess editor you can add whatever instructions as shown in the image below:

rank math htaccess editor

Afterward making the changes to your .htaccess file and save your changes and visit your site to encounter the changes.

nine How to edit .htaccess file from FTP Client – Filezilla

Editing .htaccess file from FTP requires you to first login to your File Transfer Protocol client like Filezilla. The FTP logins can be obtained from your hosting cPanel where you lot can also reset the password.

The nearly common challenge when editing .htaccess from FTP client is locating the .htaccess.

You should navigate to the server on the master menu and ensure the 'Force Showing Hidden Files' choice is checked.

After locating the .htaccess file download it and make a backup copy before y'all tin can begin editing information technology.

x Useful Tricks for editing .htaccess

Every bit mentioned above, there are a number of rules that yous tin implement in the .htaccess to change how your WordPress site works. I will explicate how to implement each of these rules in your .htaccess file.

11 Basic WordPress .htaccess Edit

When yous are editing WordPress .htaccess, you will notice the start and the end have comments equally shown below:

# Brainstorm WordPress

# .HTACCESS Rules

# BEGIN WordPress

You should avoid adding any new directives within these two lines of comments since information technology may overwrite the existing rules.

12 Tricks of Editing WordPress .htaccess

Before you lot edit any .htaccess, it is ever advisable you lot begin past creating a backup copy. After the backup copy, you can implement the following hacks in your .htaccess.

13 How to Restrict Access to WordPress wp-config.php

There is e'er an eminent danger of getting hacked if you are running a WordPress site. The best mode to safeguard your site from hackers is to tighten security in all your WordPress installation files. Of particular interest is the wp-config.php file that stores the values of your database name and the countersign. It connects your WordPress installation to the database. You lot need to restrict its access using the following code in your .htaccess file:

#restrict access to wpconfig.php

<files wp-config.php>

lodge allow,deny

deny from all

</files>

xiv How to Restrict Access to Your .htaccess file

The second nigh important file that is vulnerable to exploit past hackers in your WordPress installation is the .htaccess. WordPress .htaccess file controls how the site behaves and if it is non rubber new rules can be added that volition have a negative impact on your site. Nosotros need to protect the .htaccess file using the code below:

# restrict admission to .htaccess

<files ~ "^.*.([Hh][Tt][Aa])">

order allow,deny

deny from all

satisfy all

</files>

15 How to Stop WordPress Directory Browsing

Apache Web server allows people to access files on your site through the browser; you need to protect your WordPress installation files by stopping people from directory browsing. The access of your WordPress uploads folder can lead you to lose your images and other content in that folder and therefore information technology is necessary we stop the directory browsing using the following code in your .htaccess:

Options –Indexes

16 How to Finish Prototype Hotlinking

Some people are probable to use your images by straight hotlinking. There are a variety of means to terminate images getting hotlinked among them is a cPanel feature to stop hotlinking. Some other simple fashion to cease information technology is to add the post-obit code in your WordPress .htaccess file.

#How to stop hotlinking in WordPress

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?yoursite.com [NC]

RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?google.com [NC]

RewriteCond %{HTTP_REFERER} !^http(south)?://(world wide web.)?feeds2.feedburner.com/yoursite [NC]

RewriteRule .(jpg|jpeg|png|gif)$ – [NC,F,L]

You need to edit and replace the URL part with your domain before you can save the settings in your .htaccess.

17 How to Cease Access to WordPress Admin

Allowing admission to your WordPress admin tin can atomic number 82 to your site getting vulnerable. You demand to stop access to WordPress admin by editing .htaccess and creating an .htpasswds file that you lot should place in your root WordPress installation. In most cases you lot should place it in the public_html binder. Yous should now utilize the following code in the .htaccess to restrict access to WordPress admin area by creating an additional layer of security.

AuthName "Joe Admin Only allowed to login"

AuthUserFile C:xampphtdocs.htpasswd

AuthGroupFile /dev/zippo

AuthType bones

require user Njengah

<Files admin-ajax.php>

Gild permit,deny

Allow from all

Satisfy any

</Files>

For this illustration I used my local server, yous should supplant the authentication proper name user and the path with your respective site's values. When someone tries to visit your WordPress admin page, they will be prompted to add together a username and password as shown in the image below:

18 How to Ban IPs and Bots from Your WordPress site

One of the best ways to stop spam comments from bots is to block the IPs. This is also useful for blocking admission for people who try to hack your site. Yous tin can edit .htaccess and block users based on their IP. Adding the following code to your .htaccess blocks users by IP:

#Banning WordPress site access by IP

<Limit GET Post>

social club permit,deny

deny from xxx.30.xx.x

deny from xxx.xxx.xx.x
deny from thirty.xxx.20.x

deny from xxx.xxx.xx.x

let from all

</Limit>

You should replace the XXXX with the respective IPs addresses that you want to ban from accessing your site.

19 How to Limit WordPress File Uploads Size

Limiting the file upload size is a very important measure for membership sites. Members should only upload certain size files to salve your retention and assistance your site maintain the loading speed. You can edit .htaccess to limit the size of the upload using the post-obit code in your .htaccess:

# Limit file uploads to 20MB LimitRequestBody 20240000

This limits the upload sizes for files to xx MB

20 How to Optimize WordPress Site with GZip Compression

Saving your WordPress site bandwidth will certainly meliorate your page loading speed. Page loading speed has get a ranking indicator that Google uses to rank sites. GZip compression allows you to compress files and significantly improve your page load speed. Fortunately, you lot tin can implement GZip compression by editing the .htaccess file. Here is an example of code you lot can use in your .htaccess file.

<IfModule mod_deflate.c>
AddOutputFilterByType Deflate text/html text/plain text/xml text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
</IfModule>

It is also possible to do Gzip compression using WordPress plugins available just the .htaccess GZip pinch rids your site of unnecessary plugins.

21 How to limit WordPress login by IP Address

Securing your WordPress site from hackers is the virtually important measure when y'all have a thriving WordPress site that is earning yous some good income. The possibility of having your WordPress site hacked is eminent especially if you have not taken measures to stop hackers. Some other fashion of adding a security layer in your WordPress site is to prevent other people from logging past limiting logins to certain IPs simply. This is a foolproof way of ensuring that only you and whitelisted people can login to your site.

# Limit WordPress login admin by IP
# This goes in the /admin folder NOT root binder .htaccess
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "WordPress Admin Access Command"
AuthType Basic
<Limit GET POST PUT>
order deny,allow
deny from all
allow from twenty.20.xx.xx //( your static IP)
allow from xx.xx.xx.twenty //( Whitelist IP)
allow from xx.twenty.xx.xx //( Whitelist IP)
let from twenty.xx.xx.xx //( Whitelist IP)
allow from xx.twenty.20.xx //( Whitelist IP)
allow from xx.20.20.20 //( Whitelist IP)
</Limit>

Yous should replace the Xxx.XXX with the respective IPs that you take whitelisted. All other IPs volition be blocked from accessing your WordPress logging and thereby safeguarding your site from hackers.

22 How to Redirect Visitors to Maintenance Page in WordPress

If you are maintaining sections of your site, you can quickly redirect visitors to yous maintenance page by editing the .htaccess file. Use the following code in your .htaccess to create a redirect to your maintenance.html folio on your server.

RewriteEngine on

RewriteCond %{REQUEST_URI} !/maintenance.html$

RewriteCond %{REMOTE_ADDR} !^123.123.123.123

RewriteRule $ /maintenance.html [R=302,L]

23 How to Create 301 Redirects for quondam URLs in WordPress

Old URLs that are cleaved in your site will take a negative effect on your ranking. Information technology's advisable that all the former URLs are redirected to new URLs after irresolute the URLs structure. The easiest way to redirect URLs is using the .htaccess; the following is an example on how to create URLs redirect using .htaccess:

Redirect 301 /oldurl/ http://www.yoursite.com/newurl

Redirect 301 /category/health/ http://www.yoursite/category/health/

From the .htaccess code above you can see the first redirects the old URLs to the new one. The second line redirects the WordPress categories to the new category.

This is how yous can access and edit the .htaccess file for performing unlike functionalities on your website. Merely to make sure you do not land up in trouble, always keep the fill-in of your site and the .htaccess file.

If learned to edit correctly, .htaccess can be used for advanced settings of your website.

How To Add Code To .htaccess File,

Source: https://mythemeshop.com/blog/edit-htaccess-file/

Posted by: millswhimen.blogspot.com

0 Response to "How To Add Code To .htaccess File"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel