What is htaccess? and how to edit it? WordPress


How to Locate .htaccess in WordPress?

WordPress officially recommends NGINX & Apache for running your sites. If your WordPress site runs on NGINX, you will see no .htaccess file as it doesn’t use this file. But, if your WordPress site is hosted on Apache Web Server, you will find the .htaccess file in the root directory (public_html or www).

To access your .htaccess file, connect your server via FTP Client like FileZilla & go to your application root folder.

In my case, the root path is “/xyz.in/abc/demo”.


Also, if you see no .htaccess file, it might be hidden (it doesn’t have any file extension), mainly because the file manager hides it for security reasons.

To access the .htaccess hidden file, go to the server option (in FileZilla) and check the Force Showing Hidden Files option.


The Default WordPress .htaccess File

The default .htaccess file is located in the application root directory & is hidden in most cases but can be accessed via an FTP client like FileZilla.

If you still can’t find the .htaccess file in the root folder, you can create an empty .htaccess file using Notepad (or any text editor of your choice) and save it with the name “.htaccess” on your desktop.

Set “Save as type” to all files and upload the file to the root directory of your WordPress installation via the FTP Client.


Note: Make sure that the file name is NOT named “htaccess” – it’s written as .htaccess with a period (.) at the start.

The .htaccess is a distributed configuration file, and is how Apache handles configuration changes on a per-directory basis.

Basic WP

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

You can also create the .htaccess file for WordPress by following the steps below:

  • Visit the WordPress Dashboard.
  • Click Settings Permalinks.
  • Click the Save Changes button.

Following the above steps will generate the default .htaccess file inside the root directory.


Subfolder Example

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

SubDomain Example

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

How to Edit the .htaccess File in WordPress?

To edit the .htaccess file in WordPress, go to your root directory using the file manager provided by your WordPress hosting provider. You may also use an FTP client like FileZilla.

  • Log in to your FTP client.
  • Navigate to the ‘public_html’ folder and look for the .htaccess file.

Right-click and click on the ‘View/Edit’ option to open it in your preferred text editor.

Make the required changes and save the file.

How useful was this blog?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this blog.

Leave a comment

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