Preferred Domain



.htaccess file

What is .htaccess File and What You Can Do with It?

If your website is running on an Apache Web Server, there’s a file that can be quite useful called .htaccess. This file allows you to configure your server by redirecting traffic, forbidding hotlinks, rewriting URLs, setting up protection from bots, and more.

.htaccess can be created using any simple text editor. It’s placed in the root directory or any subdirectories and takes complete control over them. Using .htacess is convenient when you have multiple people managing different parts of your website. With .htaccess you’ll be able to let each person manage the directory they’re responsible for. When the use of .htaccess is allowed, Apache server will actually look in every directory and subdirectory for it, whether or not the files are present, and as such, this can affect performance. Before using .htaccess, make sure you actually need it. However, .htaccess also offers an array of directives that can help you prevent potential issues and make your job much faster and easier.

Below are listed the directives that you can configure with our .htaccess Generator Wizard.

Preferred Domain (www or non-www)

Redirect your website from www to a non-www and vice versa. For example, Google differentiates between a and, treating both as different websites, the redirection done for SEO.

Enable symbolic links

Symbolic links are like shortcuts used to reference to a file or a directory, so that you actually don’t have to copy or move the original.

Enable compression

Compression allows your website to load faster by reducing the size of files before they are sent by your web server. Later on, they are decompressed in a browser as the page loads. There are two methods of compression you can use: GZip or Deflate. Our .htaccess uses the DEFLATE mod, but if that doesn’t work, you might want to you use the Gzip mod.

Enable caching

You can configure browser caching with .htaccess as well. When you visit a webpage, your browser temporarily stores in its cache some of the static content such as images, CSS files, JavaScript scripts and other resources. That’s why when you visit a page for the second time it loads much faster, because there’s no need to download the files for the second time. With .htaccess you can tell browsers what files to store and for how long to store them, which will speed up your website’s loading time for visitors.

Trailing slash for URLs

The use of trailing slashes can bring a lot of confusion, but to put it simply, slashes designate directories, but never files. So /folder/foo leads to a file named foo, while /folder/foo/ leads to a directory named foo. Most of the search engines exclude the trailing slash, which can lead to a “404 not found” error. The solution to this problem is quite simple, you just need to let your server automatically add a trailing slash.

Prevent viewing of .htaccess

Enabling the use of .htaccess file can pose certain security risks, such as someone accessing it, and consequently, taking control over your web server configuration. In order to avoid such a scenario, you will want to block access to the .htaccess file.

Prevent unauthorized directory browsing

Enabled directory browsing grants access to your files for just anyone, even if you don’t have links listed to the said files. So unless you want a random person getting possession of your files, you should always have directory browsing disabled.

Prevent image hotlinking

Forbidding hotlinking prevents other websites using your images, and as a result, stealing your bandwidth.

Block unwanted bots

There are so called “bad bots”, they usually serve the purpose of email harvesting, website ripping, spammers etc. .htaccess lets you easily block any of them, and instead when a listed bot tries to access your website, they receive an error. This can greatly reduce the load on your server and save you bandwidth. The .htaccess code our tool generates blocks the most common bots crawling the Internet.

Mass redirect to another domain

Let’s say you’d like to move your website to a different domain; however, you don’t want to lose your search engine rankings that took time and effort to achieve. In that case, a few lines of code in .htaccess will redirect all your visitors to your new domain name.

Block IPs

If for whatever reason, you want to block someone from accessing your website, it can easily be done in .htaccess. All you’ll need is their IP address.

Change default index page

Your default index page is your website’s homepage. It’s what the server loads upon request, if no other page of the website was specified. The most typical names used for the default page is index.html, index.htm, index.php etc. If, for example, you’ve moved from another host and the file there is named differently, you can change the name of it in .htaccess.