What Is the WordPress .htaccess File and What Can You Do With It?

0
19
What Is the WordPress .htaccess File and What Can You Do With It?


There’s lots you are able to do inside WordPress to configure settings or troubleshoot points together with your web site. Nonetheless, typically it is advisable go into the backend and edit root recordsdata like .htaccess to finish sure duties.

On this publish, we’re going to take a better take a look at the WordPress .htaccess file — what it’s, the place you’ll discover it, and find out how to use it to safe, optimize, and troubleshoot errors in your web site, amongst different issues. 

What’s the WordPress .htaccess File?

.htaccess is an Apache-based configuration file that provides WordPress customers the power to do issues like:

The .htaccess file can also be useful in troubleshooting WordPress errors. As an example, resetting the .htaccess to the default can repair the five hundred inside server error in addition to the 403 forbidden error if nothing else has labored. 

In case your WordPress web site is hosted on an Nginx net server, you received’t have an .htaccess file. Nonetheless, it’s best to be capable to do these kinds of configurations on the server degree in different methods.

The place Is the .htaccess File in WordPress?

You received’t discover the .htaccess file inside WordPress out of the field. To find the file, you’ll want to enter your server recordsdata. You may entry them utilizing FTP or a File Supervisor in your cPanel. 

For the remainder of this publish, I’ll use SiteGround hosting to reveal find out how to discover and use the .htaccess file. In case your web site is hosted elsewhere, the situation of your web site instruments would possibly differ, however the the rest of the steering on this publish will likely be related.

To find the .htaccess file, open your FTP or File Supervisor. You’ll discover each underneath Website Instruments and Website.

In SiteGround's control panel, users can access their root folder under Site and FTP or File ManagerIn SiteGround's control panel, users can access their root folder under Site and FTP or File ManagerIn SiteGround's control panel, users can access their root folder under Site and FTP or File Manager

Choose the one you need to use. Then, go to the foundation of your web site, which is a folder labeled public_html

SiteGround users will find the .htaccess file in the root (public_html) of the serverSiteGround users will find the .htaccess file in the root (public_html) of the serverSiteGround users will find the .htaccess file in the root (public_html) of the server

If you don’t see the file there, examine to ensure you’re utilizing an Apache net server. In case your hosting makes use of Nginx as an alternative, that’s why you aren’t seeing the file.

In case you do have an Apache server, then the file may be hidden. The main dot in .htaccess normally means the file will likely be hidden from view, however that’s not at all times the case relying in your cPanel’s default settings.

Search for a settings or preferences menu in your FTP or File Supervisor. It is best to discover a setting that allows you to present hidden recordsdata. It additionally could seem as an elective checkbox when opening your server recordsdata for the primary time.

How Do You Edit the .htaccess File?

You may manually edit the .htaccess file out of your FTP or File Supervisor. An alternative choice is to edit it utilizing a WordPress plugin

Earlier than making any modifications to the file, again up your web site. You can also make a backup from inside your hosting account or use a WordPress backup plugin.

Manually Enhancing the .htaccess File

There are 3 ways to open the .htaccess file out of your FTP or File Supervisor:

  • Proper-click on the file title and click on Edit
  • Choose the file and click on the pencil icon within the toolbar
  • Double-click on the file
Click the pencil icon to edit the .htaccess fileClick the pencil icon to edit the .htaccess fileClick the pencil icon to edit the .htaccess file

You can also make modifications to this file simply as you’d in a textual content or code editor.

An example of what the .htaccess file looks like in the SiteGround File Manager editorAn example of what the .htaccess file looks like in the SiteGround File Manager editorAn example of what the .htaccess file looks like in the SiteGround File Manager editor

Listed here are some examples of instructions you would possibly need to add to the file: 

To blacklist an IP handle:

1
order enable,deny
2

3
deny from 76.106.149.140
4

5
enable from

To implement a 301 redirect: 

1
Redirect 301 /old-url https://yourdomainname.com/new-url

To implement HTTPS:

1
RewriteEngine On
2

3
RewriteCond %{HTTPS} off
4

5
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Enhancing the .htaccess File with a Plugin

To edit the .htaccess file with a plugin, set up and activate Htaccess File Editor inside your WordPress web site. 

You’ll discover the settings panel for the plugin underneath the Settings > WP Htaccess Editor. Learn by means of and comply with the disclaimer that explains what it is advisable do in case your web site goes down when modifying the file.

This may then unlock a model of the .htaccess file editor inside WordPress.

The WP Htaccess Editor plugin brings the .htaccess file editor into WordPressThe WP Htaccess Editor plugin brings the .htaccess file editor into WordPressThe WP Htaccess Editor plugin brings the .htaccess file editor into WordPress

Make your edits to the textual content. Click on Check Earlier than Saving to make sure your modifications do what you need them to do and don’t break your web site. 

In case you’re glad with the edits, click on Save Adjustments.

How Do I Create a New .htaccess File for My WordPress Website?

There are two methods to create a brand new WordPress .htaccess file: 

Possibility 1: Manually Create a New File 

There are a few explanation why folks want new .htaccess recordsdata. Both they’ll’t discover the file on the server to change or they need to add one to a subdirectory on the server. Whereas it’s true that the .htaccess file usually lives within the root folder, it’s also possible to add one to different areas with a view to set directory-level guidelines and permissions. 

To create a brand new file, you’ll have to open the FTP or File Supervisor. You then have two methods to manually add it. 

The primary approach to do it’s so as to add a New File. In SiteGround, the icon is a web page with a small plus-sign icon within the bottom-right nook.

In the Siteground File Manager, users can click New File to create a blank fileIn the Siteground File Manager, users can click New File to create a blank fileIn the Siteground File Manager, users can click New File to create a blank file

Click on the icon and a brand new file will open for modifying. 

Paste the next default .htaccess code into the file: 

1
# BEGIN WordPress
2

3

4

5
RewriteEngine On
6

7
RewriteBase /
8

9
RewriteRule ^index.php$ - [L]
10

11
RewriteCond %{REQUEST_FILENAME} !-f
12

13
RewriteCond %{REQUEST_FILENAME} !-d
14

15
RewriteRule . /index.php [L]
16

17

18

19
# END WordPress

If you wish to make customizations or add the rest to the file, achieve this now. In any other case, save your modifications and exit out of the editor. 

The opposite means so as to add a brand new file is by importing one. In SiteGround, the icon is a clean web page with an arrow pointing upwards.

In the SiteGround File Manager, users can upload a premade file to the rootIn the SiteGround File Manager, users can upload a premade file to the rootIn the SiteGround File Manager, users can upload a premade file to the root

You may create an .htaccess file utilizing your laptop’s textual content editor or phrase processor. Then save the file with the precise title .htaccess (no different extensions). 

Go to the foundation of your web site. Then click on the File Add icon to insert it.

The opposite motive you would possibly want a brand new .htaccess file is that if your web site is experiencing an error. If the error exists in that file, then changing it with a clear one will restore the error. 

To do that, log into WordPress. Then go to Settings > Permalinks.

The WordPress Permalinks settings page provides a quick way to create a new .htaccess fileThe WordPress Permalinks settings page provides a quick way to create a new .htaccess fileThe WordPress Permalinks settings page provides a quick way to create a new .htaccess file

Choose any of the opposite permalink buildings. Then click on Save Adjustments on the backside of the web page. 

Anytime the permalinks change in WordPress, the .htaccess resets. This may filter out any customizations made by you, a plugin, or a hacker, and reset the file to its default state. 

In case you don’t discover an .htaccess file in your server, that is one other methodology you need to use to immediately generate one. Simply bear in mind to alter your permalink construction again to the popular format after the file has been generated.

Abstract

The .htaccess file won’t get quite a lot of use, however it might allow you to make essential modifications to your web site in a matter of seconds. Whether or not you need to strengthen safety, enhance efficiency, troubleshoot an error, or one thing else, most of this stuff could be achieved by including a number of new traces of code to the WordPress .htaccess file. Realizing what it does, the place to search out it, and find out how to responsibly use it would make sure you profit from its capabilities.



Supply hyperlink

LEAVE A REPLY

Please enter your comment!
Please enter your name here