What is .Htaccess? (+Helpful .Htacess Codes)

As Dopinger, we aim to provide you the most useful information about SEO related topics, and this time is not an exception. In this article, we are going to mention one of the more technical subjects of SEO. If you ever wondered what is Htaccess and what does it do, then keep reading to find out. 

What is .htacess?

Htaccess, a.k.a Hypertext Access is the file that enables setting changes on the web used by most network servers, especially Hypertext Access and Apache. You can do a lot of editing, authorization, and restriction operations on your sites with .htaccess file. It is very useful with 100s of different commands, requires using different encodings to make the necessary applications. With the .htaccess generator, you can create the appropriate hypertext access file for your site without the need for code information online.

uses of htaccess

The Hypertext Access is a directory-level configuration file supported by a particular web server, enabling management independent of web server configuration. It is located in the web directory and overrides some of the general configuration settings of the webserver for its directory, allowing new rules to be added. 

The original purpose of the .htaccess file is that access to each folder can be controlled individually, for example, password protection can be added to a folder. However, hypertext access files can contain content types, character sets, CGI practitioners and many more regulatory parameters.

What Can Be Done With The Htaccess File

Here’s a list of what are the things you can do with a hypertext access file: 

  • SEO compatible link structure
  • Hotlink blocking
  • Hiding files
  • Error pages
  • Folder authorization limitation
  • Blocking enemy bots
  • WWW configuration
  • Security operations such as file encryption and password protection
  • Domain forwarding
  • Data compression
  • Create a maintenance page
  • Spam blocking

And there are many more things you can do with Htaccess.

how to find htaccess in wordpress

Where to Find the Htaccess File?

You can find the .htaccess file in the main document directory of the website. To view the file, first, log in to your cPanel management panel and click on the File Manager icon. Then check the “Show Hidden Files” option, and select the document directory and click on the “Go” button. You can view and edit the .htaccess file under the public_html folder.

Note: If your file is not located in the main directory or other directories, you can create your own name as “.htaccess” and enter your codes.

Htaccess Codes For Some Purposes 

Authorization and Authentication

A directory can be protected with a password by using the .htaccess file. In this case, the .htpasswd file, which contains the usernames and passwords, is often included with it.

URL Redirection (Rewriting URL)

With the URL forwarding function, long addresses can be forwarded to shorter, memorable addresses or different addresses. For URL forwarding, paste the following code into your .htaccess file by specifying your domain names:

RewriteEngine On

ReWriteCond% {HTTP_HOST} ^ (www \.)? yourolddomainname\.com $ [NC]

ReWriteRule ^ (. *) $ Http://www.yournewdomainname.com/$1 [R = 301, L]

Preventing Access to Files and Directories

Users can be denied access to a directory or allowed by their IP address or domain name. In this way, traffic from bots, search engines, spiders and spam can be restricted. Create a file called .htaccess in a folder where you want to block its files and directories and enter the following codes in it:

deny from all

To allow access from a specific IP address or IP block:

deny from all

allow from 192.168.1.10 # single ip address

allow from 192.168.1.0/24 # ip block

To restrict access to just one file:

<Files hiddenfile.html>

Order allow, deny

Deny from all

</ Files>

Directory Listing

Htaccess can determine which of the files in a folder will appear first. For example, changing the home page address from index.htm to welcome.html. As an example, you can use the following code:

DirectoryIndex welcome.html

Special Error Messages

Htaccess allows to change server-side error pages such as “301 Moved Permanently”, “404 Not Found” etc. Thus, you can view the error pages you have prepared for your visitors.

RECENT POSTS
What is Interaction to Next Paint (INP) & How to Optimize It?
What is Interaction to Next Paint (INP) & How to Optimize It?

Google recently changed the balance by introducing a metric called next-paint engagement (INP) to track page experience. INP stands out as an empirica...

H1 Tag Missing Or Empty Warning
H1 Tag Missing Or Empty Warning

The digital world has wonders, however, it is not perfect. Sometimes there can be problems. In this world where algorithms waltz and crawlers choreogr...

If you want to change the 404 error page and if your error.html page is located in the main directory of your website, you can use the following code:

ErrorDocument 404 error.html

If the error.html page you have created is located in “documents” or in another directory of your website:

ErrorDocument 404 /documents/404error.html

Pro Tip: You can check more codes from the WordPress support page.

codes for htaccess

How to Use Htaccess in WordPress?

Most of the blogs or websites use WordPress. In WordPress, the .htaccess file exists mostly for rewriting URLs, clean them up, and make them more readable by users and search engines. To Access Htaccess, go to the Settings > Permalinks section of the WordPress Administration. There you will see the option to select your URL structure. The good news is WordPress will automatically rewrite your .htaccess file and handle the URL structure that you selected.

Sometimes, WordPress is unable to write to the file and it asks you to write it manually. Keep in mind that it is risky to Manually edit the .htaccess file because it can create significant server errors if you configure them in an incorrect way. That’s why you should make sure to only copy the contents that WordPress suggests to you.

Conclusion

As you can see, .htaccess can look complicated and hard, but once you look for the relevant codes and understand the working mechanisms, it will feel way easier. Needless to say, you will hugely benefit from the htacess file in your personal blog or website. If you want to learn more about technical SEO stuff like htaccess, we would highly recommend you to check out our article about Sitemaps. Also, if you need a visual explanation of what is htaccess, check this video out by WPLearningLab :

Frequently Asked Questions About

The file can be used to do SEO-related things like redirects. You can avoid 404 error messages and let crawlers know which pages they need to index.

It stands for Hypertext Access.

A lot of people use Hypertext Access files for SEO and purposes and they are a staple when it comes to specific things like controlling access, redirecting, etc. So, hypertext access it is reliable and safe to use them.

Cihat Kısa

Posts: 18

I was born in a city in Turkey called Konya. When I was six, we have moved to Istanbul. Before moving to Istanbul, my childhood dream was to develop computer programs, websites, or games. After a few years, I started designing some websites and then learned web development to create something that... Read More

RECENT POSTS
Be the First to Comment on What is .Htaccess? (+Helpful .Htacess Codes)

Your email address will not be published. Required fields are marked *

(Total: 47 Average: 5 )

No comments to show.