Enabling htaccess file in Apache on Windows

Enable htaccess file on Apache2 in Windows. By default XAMPP and similar Apache Web Servers that can be run from Windows do not have mod_rewrite enabled. This causes Apache to ignore an .htaccess file. In the following simple solution, I show you how to enable mod_rewrite to enable the use of .htaccess on Apache servers in Windows like XAMPP. Moreover, this allows you to create nice permalinks for software like WordPress.

What is an htaccess file?

An htaccess file, also known as a hypertext access file, is a configuration file used on web servers running the Apache software. It allows website administrators to control and customize the server's behavior for specific directories. The settings used in an htaccess file can override the global configuration of the server, and they apply to the directory in which the file is located and its subdirectories.

Common use cases include:

  • URL Rewriting: It enables the modification of URLs, often used for creating user-friendly and search engine optimized URLs.
  • Authentication and Authorization: You can restrict access to certain parts of your website by requiring a username and password.
  • Custom Error Pages: You can customize error pages for various HTTP status codes.
  • Redirects: You can set up redirects for specific URLs, helping with site migrations or changes.
  • Security: Implement security measures such as blocking specific IP addresses or preventing directory listing.

It's important to note that not all web servers support .htaccess files, and their use is specific to Apache servers. Other servers have different ways of achieving similar configurations.

How to enable htaccess on Apache2 in Windows

To enable .htaccess on Apache2 servers such as XAMPP in Windows, follow these steps:

  1. Using a text editor, open the httpd.conf file: In XAMPP, this file is located in the apache/conf directory.
  2. Find the following line of code.
    #LoadModule rewrite_module modules/mod_rewrite.so
  3. Remove the # from the line as seen below to enable the mod_rewrite module.
    LoadModule rewrite_module modules/mod_rewrite.so
  4. Save the changes you made to the httpd.conf file and close it.
  5. Restart Apache: Restart the Apache server for the changes to take effect.
    Note: You can also do this through the XAMPP control panel.
  6. Create .htaccess file: Create a new file in your website's root directory called .htaccess and add your rewrite rules to this file.

Now you have successfully enabled htaccess on an Apache2 webserver. You can use this file located at your root directory to control access to subdirectories, redirect URLs, restrict file access, and more.

Enable htaccess WordPress

Enabling and using an .htaccess file for WordPress sites and blogs is a common practice. It's necessary to enable for certain features such as to allow for the use of pretty permalinks in WordPress. Here are some steps to make sure you've enabled the use of .htaccess files for an Apache WordPress based site:

    1. Locate or Create .htaccess File: Check if your WordPress installation already has an .htaccess file. It's typically located in the root directory of your WordPress installation. If you don't have one, you can create a new file and name it .htaccess.
    2. Set .htaccess File permissions to 644: Ensure that the file has the correct permissions. Usually, setting the file permissions to 644 is appropriate. You can do this using an FTP client or through your hosting control panel.
    3. Configure Permalinks in WordPress: One common use of .htaccess in WordPress is to configure permalinks. To do this:
      (1.) Enter your WordPress admin dashboard.
      (2.) Navigate to Settings -> Permalinks and choose your desired permalink structure. WordPress will automatically update your .htaccess file to reflect the chosen structure.
      (3.) After making changes to the file, make sure to test your site to ensure that everything is working as expected.

If all went well, you should be able to use htaccess files on your server allowing you to create and use those nice pretty permalinks within WordPress.

Note: These instructions are for Apache based servers, only. If you are using a server other than Apache, such as Nginx, none of this will apply as the configuration process will be different.