Pinterest Stumbleupon Whatsapp
Ads by Google

how to create .htaccess fileThe .htaccess (also known as Hypertext Access) file is a Web server configuration file that is used to control the behavior, security and performance of a site. Most webmasters create .htaccess file and use this file to control their sites and make sure everything is in good hands.

While there are many ways that you can configure your .htaccess file, the most common usage can be categorized into the following 5 scenarios:

Authorization and authentication

The .htaccess file serves as a control to authorize and authenticate who can view your site (or certain page of the site). While you want your site to be visible to everyone, there may be times when it is visited by spambots and you start to receive many spam mails, comments, form submissions and so on. With the .htaccess file, you will be able to block access that comes from unauthorized sources (such as particular domain names or IP addresses).

Rather than blocking access, you can also set a password (together with the .htpasswd file) for your site and grant only authorized personnel to visit your site. This can be used on a multi-author blog or a collaboration site.

Customized error responses

In the event that your visitor mistyped your site’s URL or you have accidentally deleted a page from the server, the visitor will see a ‘HTTP 404 Not Found’ page. This page is ugly and always turn people off. With the .htaccess file, you can easily direct your visitor to a beautifully designed 404 page How To Make a Great 404 Error Page & 10 Examples How To Make a Great 404 Error Page & 10 Examples Read More and make them stay longer on your site.

Redirection

If you have migrated to a new domain name, or have changed the permalinks structure of the whole site, you can use the .htaccess file to direct your reader to the new address and also to inform the search engine (especially Google) of the change in address. This is, so far, the best way to retain your readers and won’t lose any of your search engine rankings.

Ads by Google

Create a nice clean URL

Some of the commonly used CMS software (such as WordPress) have already included this feature in , but in some cases where the platform (forum software) that you are using does not create a nice clean URL, you can use the .htaccess file to rewrite the ugly URL and present your reader with a short, clean and nice one.

Performance

The .htaccess file can help you to reduce your site bandwidth usage and make it load faster and perform better. If you are hosting your files on a third-party server and you need to pay for the bandwidth (such as Amazon S3), using the .htaccess file is also a good way to help you to save costs.

There are mainly two areas where you can increase the performance of the site:

  • Cache control – specify what and how long a file can be cached and prevent the server from querying the database unnecessarily.
  • Compression – compress your file so that it is sent to the browser in a smaller piece.

How Do I Create .htaccess file (if I am not technically inclined)

I am not going to go through all the technical details and expect you to learn everything in one post. Instead, I am going to recommend to you one software (website) that you can use to create your .htaccess file easily (or edit the existing one), even if you don’t have any technical or programming knowledge.

The .htaccess file generator is a simple, but detailed Web form that you can use to specify your site’s needs and get it to generate the .htaccess code. All you need to do is to copy and paste the generated code into a text file, save it as .htaccess and upload to your Web server.

There are plenty of options that you can configure in the software. It will take a long article to discuss them all. Below I have listed some of the more important options for reference:

Authentication

htaccess-authenticate

Fill in the respective fields on who is allowed to view and who is not.

Cache Control

create .htaccess file

This option determine if there should be a cache control and how long should the cache time be.

Error page

htaccess-404

Set the custom page to appear when there is an error response.

Redirection

htaccess-redirect

If you have moved your site/document, this is where you specify the new URL.

Generated htaccess code

htaccess-code

Once you are done with the configuration, simple click the ‘Generate htaccess file’ button to generate the code. You just need to copy/paste the code to your htaccess file, and that’s it.

In conclusion, I can’t emphasize enough the importance of having a .htaccess file for your site and how easily and quickly you can create a .htaccess file with the .htaccess file generator. If you have not made good use of the .htaccess file to enhance your site’s performance, I urge you to do it now.

What other methods have you used to create or edit .htaccess files easily and quickly?

  1. rajiv
    October 14, 2016 at 10:52 am

    The .htaccess file generator is not working

  2. Kate Lennon
    May 5, 2016 at 2:56 am

    You say "copy/paste the code to your htaccess file, and that’s it."

    There is no .htaccess file in my directory. Does that mean I have to create a htaccess directory and upload the code on a text file= And if so, what do I name this file?

    • Brian
      June 27, 2016 at 9:29 pm

      You need to create a new file in your text editor and paste the info. Save the doc like .htaccess(name of the doc) and upload to your "public_html" directory.

  3. Nikhil
    March 28, 2016 at 6:54 am

    Url is not working showing below error:
    Not Found

    The requested URL /index-nojs.php was not found on this server.

  4. rolf
    January 7, 2016 at 3:29 pm

    Not Found

    The requested URL /index-nojs.php was not found on this server.

  5. Sarah Ali
    October 2, 2015 at 4:24 pm

    Thanks!!

  6. Mohit Arora
    May 24, 2015 at 7:47 am

    Thanks for sharing this informative article. Very deeply explained. I would like to add one more thing that we can do using

    htaccess file - Adding MIME Type that our server is not setup to deliver. E.g.

    AddType text/css .css

    AddType text/x-component .htc

    AddType application/x-javascript .js

    AddType application/javascript .js2

    AddType text/javascript .js3

    AddType text/x-js .js4

    etc.

    Source: http://catchupdates.com/what-is-htaccess-file/

  7. Buddhi_Kasun
    March 4, 2015 at 2:46 pm

    Pretty cool.. thanks.

  8. Jignesh Adhyaru
    February 10, 2010 at 8:40 am

    This is really nice info, but i wanted my media files, particularly mp3s not to get listed, but enable them to play through embedded player on my webpage enabled through wordpress.

    Is there any code for this?

    Hope there is some...

  9. kostas
    January 16, 2010 at 9:17 am

    thnx!

  10. Kevin
    May 25, 2009 at 11:41 am

    This is a very cool article, just what I needed to get started on htaccess.

  11. Jash Sayani
    February 16, 2009 at 2:50 pm

    Just customized my WordPress .htaccess file yesterday !

    • piddubetskyy
      January 12, 2010 at 2:13 pm

      and how did it worked for you?
      I open mine and its empty,
      I add couple of lines

      php_value upload_max_filesize 20M
      php_value post_max_size 20M

      and the whole blog stops working

  12. Deep
    February 16, 2009 at 12:30 pm

    Thx Cool

Leave a Reply

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