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
.htaccessfiles 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/orpublic_html/).
Step-by-Step: Locate .htaccess on a Linux Server
Connect to the server via SSH. The
.htaccessfile resides in the website's document root or in subdirectories beneath it. Apache HTTP Server reads.htaccessfiles from every directory along the request path.Search for all
.htaccessfiles under the document root using thefindcommand. The.htaccessfilename starts with a dot, which makes it a hidden file on Linux and macOS.find /var/www/example_com/ -name ".htaccess" -type fThe command outputs the full path to every
.htaccessfile found:/var/www/example_com/public_html/.htaccess /var/www/example_com/public_html/admin/.htaccessList hidden files in a specific directory with
ls -lato confirm the.htaccessfile exists. The-aflag shows hidden files thatlshides by default.ls -la /var/www/example_com/public_html/The
.htaccessfile appears in the listing with its permissions, owner, and modification date.
Step-by-Step: Locate .htaccess on Shared Hosting (cPanel)
Log into the cPanel control panel and open File Manager. Navigate to the website's document root, typically
public_html/.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.Look for the
.htaccessfile in the directory listing. The file appears alongsideindex.html,index.php, and other root-level files. If no.htaccessfile exists, create one by clicking + Fileand entering.htaccessas the filename.
Step-by-Step: Locate .htaccess via FTP
Connect to the server using an FTP client (FileZilla, Cyberduck, or WinSCP). Navigate to the website's document root directory.
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.
The
.htaccessfile 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.htmlNavigate 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.