.htaccess
(Last Updated On: April 12, 2021)

The .htaccess file gives content developers and server administrators a great way to redirect website URLs, control access to admin panel, rewrite URLs among other awesome benefits. In fact, if you have deployed WordPress, Joomla or Drupal or any other content management software, you may have seen this file in certain directories. But what is .htaccess? What exactly can you use it for? And how can you activate it? We’ll cover all these questions in this post.

What Is .htaccess?

The .htaccess file, shortening for Hypertext Access. It is a configuration file used to detail how data on a website is presented within a web browser and how visitors interact with your website. Because the file contains configuration information and other security features, so it’s usually hidden from your view. In fact, the dot at the start of the file name (.htaccess) means that the file is hidden.

What is .htaccess used for?

As briefly highlighted before, the .htaccess file has some great benefits which are super important to you.

To Rewrite Links

Every website administrator strives for a consistent look to their website and having user-friendly features. This should be your desire too. With .htaccess, you can modify and simplify website URLs and web pages thus making browsing an easier experience for your users. See below examples:

Regular URL without .htaccess: http://www.sammy.com/ty/itemN999RTYO5M/ref=qw_jk_pp_yu
URL Rewrite by .htaccess: Sammy.com/beauty_and_posture/specific_beauty/hair_supply_glue_blue

This URL shows you that it is custom and simplified for the user. Every directory a user needs to make purchase is set up and this is easily done using the Rewrite feature of .htaccess. This feature communicates to the user what stage they are at in your website. Therefore, if your user is on the ‘About Us’ page, they will see this at the address bar. You want to also ensure that each URL matches the page location. Long and complex URLs don’t make for easy browsing experience.

URL Redirection

Websites are constantly updated with newer information especially for ecommerce sites where the inventory constantly changes. To better guide your customers to newer updates of your products, you can use a permanent 301 redirect. This URL will communicate to the search engine and your visitors the redirected link which replaces the old information. Redirects impacts a number of aspects for your website – server load, site speed, SEO, indexability, crawlability, UX, and so on.

In these examples, we’ll be using case.com but remember to replace this with your own domain name.

301 redirect – This is for permanent redirects only. It updates the search engines to use the new link.

Redirect 301/http://case.com/

302 redirect – This is for temporary redirects. It is not for long term redirects because the original URL will continue to be considered valid by search engines. However, it is useful for SEO purposes. For instance, when you have a temporary landing page and want to switch back later to your main landing page.

Redirect 302/http://case.com/

404 Page – This will redirects the error message. Instead of a 404 not found error page, this will redirect to your home page instead.

404 http: //case.com/

To know more about Htaccess 301 redirects go here. You can also visit our blog to learn how to deal with broken links.

Authentication

With the .htaccess file, if you have sensitive information on your website, you can use it prevent unauthorised visitors from accessing your administrator panels, staging/developing and testing areas. For more information such as how to accomplish this, check this out.

IP Whitelisting

Another great feature of .htaccess is that you can set up your admin panel or any folder to be accessible by only yourself and specified guests. You can also block everyone except visitors on a specific IP address, this is called whitelisting. Those that are not on your trusted list will be refused access.
When Is .htaccess Best Used?

When content providers need to make configuration changes to the server from the pre-directory, but do not have root access on the server system, the .htaccess is best used then. Should the server administrator not be able to make frequent configuration changes, it might be desirable to permit individual users to make these changes in .htaccess files for themselves. This is particularly true, for example, in cases where you’re hosting multiple user sites on a single machine, and want to make your users able to alter their configuration.

However, in general, any configuration that you would consider putting in a .htaccess file, can also be done in the directory section in your main server configuration file. This means that the use of .htaccess file should be avoided once it is possible.

How to Access a .htaccess File?

You can make changes to the .htaccess file using either the file manager within your hosting account or by accessing your hosting via FTP. Because the .htaccess file is hidden, it may not be visible by default. Don’t worry, it is still accessible. Your FTP client or File Manager usually have a setting for hidden files under “show hidden files”. This is in different places based on your program however, it is usually in “Preferences”, “Settings”, “Folder Options” or “View” menu.

If you do not have the .htaccess file, you can create it in a text editor. Ensure to name it only .htaccess without any other extension or name and then upload it to your site through an ftp client.

Conclusion

The .htaccess file is a great way for content developers and server administrators to secure their directories while making the browsing experience effortless with URL rewrite and redirect.