How to locate the .htaccess file

Find the .htaccess file on Linux servers via SSH and on shared hosting through cPanel, Plesk, or FTP file managers.

Find existing .htaccess files on Apache HTTP Server installations using command-line tools on Linux or file managers on shared hosting control panels.

Prerequisites

  • SSH access to the server, oraccess to a hosting control panel (cPanel, Plesk, DirectAdmin).
  • Knowledge of the website's document root path (commonly /var/www/html/ or public_html/).

Step-by-Step: Locate .htaccess on a Linux Server

  1. Connect to the server via SSH. The .htaccess file resides in the website's document root or in subdirectories beneath it. Apache HTTP Server reads .htaccess files from every directory along the request path.

  2. Search for all .htaccess files under the document root using the find command. The .htaccess filename starts with a dot, which makes it a hidden file on Linux and macOS.

    find /var/www/example_com/ -name ".htaccess" -type f

    The command outputs the full path to every .htaccess file found:

    /var/www/example_com/public_html/.htaccess
    /var/www/example_com/public_html/admin/.htaccess
  3. List hidden files in a specific directory with ls -la to confirm the .htaccess file exists. The -a flag shows hidden files that ls hides by default.

    ls -la /var/www/example_com/public_html/

    The .htaccess file appears in the listing with its permissions, owner, and modification date.

Step-by-Step: Locate .htaccess on Shared Hosting (cPanel)

  1. Log into the cPanel control panel and open File Manager. Navigate to the website's document root, typically public_html/.

  2. Enable hidden file visibility. Click Settings(top-right corner) and check Show Hidden Files (dotfiles). Click Save. File Manager now displays files starting with a dot, including .htaccess.

  3. Look for the .htaccess file in the directory listing. The file appears alongside index.html, index.php, and other root-level files. If no .htaccess file exists, create one by clicking + Fileand entering .htaccess as the filename.

Step-by-Step: Locate .htaccess via FTP

  1. Connect to the server using an FTP client (FileZilla, Cyberduck, or WinSCP). Navigate to the website's document root directory.

  2. Enable hidden file display in the FTP client. In FileZilla, go to Server> Force showing hidden files. In Cyberduck, go to View> Show Hidden Files. FTP clients hide dotfiles by default.

  3. The .htaccess file appears in the root directory listing once hidden files are visible.

How to Verify .htaccess File Location

Confirm the correct .htaccess file by adding a temporary comment and checking for the expected behavior. Open the .htaccess file and add a test directive:

# Test: this line confirms the correct .htaccess file
ErrorDocument 404 /test-404.html

Navigate to a non-existent URL on the site. If Apache serves the custom 404 page (or returns a 500 error because test-404.html does not exist), the .htaccess file is active. Remove the test directive after verification.

Common Issues When Locating .htaccess Files

The .htaccess file does not appear in the directory listing.The file is hidden because its name starts with a dot. Enable hidden file visibility in the file manager, FTP client, or use ls -a on the command line.

The .htaccess file exists but Apache ignores it.The AllowOverride directive in httpd.conf is set to None. Apache does not read .htaccess files when AllowOverride None is active. Change AllowOverride to All or to the specific override classes needed.

Multiple .htaccess files exist across directories.Apache HTTP Server reads .htaccess files from every directory in the request path and applies them in order from parent to child. Child directives override parent directives for the same settings. Use find to list all .htaccess files and consolidate where possible.