Domain Email & Office Website WordPress Hosting VPS
Go back
.com
$ 4.99 $ 26.99 /1st year
.one
$ 4.99 $ 16.99 /1st year
Go back
Log in
Control Panel Webmail Website Builder Online Shop File Manager WordPress

What is .htaccess? + 8 useful hacks to apply

Read more about .htaccess and learn how to create a file

There are many files behind your website, like the .htaccess file. Are you curious about what this file exactly is? Or would you like to know how to create a .htaccess file yourself? We will tell you more about .htaccess in this article.

vector

Brief Summary

Glossary

.htaccess is a file that allows you to give instructions to Apache servers, for example, setting up redirects. You will find the .htaccess file in the root folder of your website.

What is .htaccess?

.htaccess is the abbreviation for HyperText Access. It is a file that allows you to give instructions to an Apache server. The file has no name because ‘.htaccess’ is an extension.JPG, for example, is also a file extension.

Building your website on ultra-fast web hosting

Building your website on ultra-fast web hosting

Make your dream a success. Host your site on fast, secure and reliable servers.

Get started
  • High-performance SSD servers
  • Easy-to-use Control Panel
  • Free website builder
  • Free SSL certificate
  • Daily backup
  • 24/7 support

What can you do with .htaccess?

.htaccess allows you to give different instructions to the server. Among other things, you can:

  • Redirect visitors to another page;
  • Create your own error page;
  • Protect specific folders with a password;
  • Blocking IP addresses;
  • manage cache.

Where can you find .htaccess?

The .htaccess file is usually located in the root folder of your website. You access the root folder using an FTP programme, such as FileZilla, CuteFTP and FlashFXP. Are you a customer of one.com? You can use the File Manager.

How do you create a .htaccess file?

At one.com, you create a .htaccess file via the File Manager. Does a .htaccess file already exist? You don’t need to do anything. Follow these steps to make a .htaccess file at one.com:

  1. Log in to the one.com Control Panel.
  2. Open the File Manager.
  3. Click on ‘Create’ > ‘File’ > ‘Other’.
  4. Name the file ‘.htaccess’ and press enter.

Are you not a customer of one.com? Create a .htaccess file via Notepad++, for example. Save a file as .htaccess and upload it via FTP to the root folder of your website.

An example of a .htaccess file

Are you curious about what a .htaccess file looks like? Below is an example of a .htaccess file.

# Custom error page for 404- error
ErrorDocument 404 /errorpage.html

In the example, the line with # explains the code. So the server does nothing with this line. The code below it tells the server what task to perform.

8 useful hacks for .htaccess

As you can see in the above example, a .htaccess file is not empty. The file contains rules that the Apache server executes. Do you want to know what you can add to .htaccess? Here are some helpful hacks.

1. Forwarding traffic

You redirect traffic (visitors and search engines) to another page or website via a redirect.

301 redirect

With a 301 redirect, you permanently redirect visitors from page A to page B. Use the following code:

Redirect 301 /old-page.html https://www.yourdomainname.com/new-page.html

Replace ‘/old-page.html’ with the current page without ‘www.yourdomainname.com’. For ‘https://www.yourdomainname.com/new-page.html’, use the full URL to which the old page should point.

Referral to www.yourdomainname.com

Search engines like Google see ‘www.yourdomainname.com’ and ‘yourdomainname.com’ as 2 different websites. So it is better to use 1 variant. Use the following codes to redirect to one of the variants. Remember to replace ‘yourdomainname’ with your own domain name.

A domain name with www

RewriteEngine On
RewriteCond %{HTTP_HOST} .^www.yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomainname.com/$1 [L,R=301]

A domain name without www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^{HTTP_HOST} [NC]
RewriteRule ^(.*)$ http://yourdomainname.com/$1 [L,R=301]

Rewriting to HTTPS

Do you have SSL activated? You must forward traffic from HTTP to the secure HTTPS. Place the following code in the .htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

2. Creating an error message

You can also use .htaccess to create error messages. Below are the options you can use.

Using a different error message text

Most websites have a default error message enabled. This is a white page with a piece of text. Do you want to change this text? Use the following code. Replace ‘error code’ with the correct error code.

ErrorDocument 'error code' "This is where your text will appear."

Showing a custom error page

Have you created your own error page? You can display it by adding the following code to the .htaccess file. Replace ‘http://yourdomainname.com/refferingpage.html’ with the page showing the error message.

A 403 page

ErrorDocument 403 http://yourdomainname.com/refferingpage.html

A 404 page

ErrorDocument 404 http://yourdomainname.com/refferingpage.html

3. Securing a folder

Do you want to block specific folders from others? In this case, you can only access the folder with a login name and password. You can use the following code to do this:

REQUIRE valid-user
AUTHTYPE basic
AUTHUSERFILE /Path to protected directory/.htpasswd
AUTHNAME "Protected folder"

However, there are other steps you need to follow. To best help you, you should use this guide.

4. Blocking an IP address

It is possible to block one or more unwanted IP addresses. To do this, add the following code to the .htaccess file. Replace ‘IP address’ with the address you want to block.

Order allow,deny
Deny from 'IP address
allow from

Other hacks

Besides the above hacks, there are many more possibilities with the .htaccess file. We recommend that you search online for specific features for .htaccess. There is a lot of information out there. Or use one of our tutorials:

A conclusion

.htaccess is a helpful application to let an Apache server perform various tasks. For example, you can redirect traffic to other pages, display its own error page, password-protect folders, block IP addresses and manage cache. Hopefully, you can use the helpful .htaccess hacks from this article for your own website. Good luck!

Building your website on ultra-fast web hosting

Building your website on ultra-fast web hosting

Make your dream a success. Host your site on fast, secure and reliable servers.

Get started
  • High-performance SSD servers
  • Easy-to-use Control Panel
  • Free website builder
  • Free SSL certificate
  • Daily backup
  • 24/7 support