Do you want to create .htaccess file on WordPress? This blog will help you to do so.
Upon installing WordPress on your hosting account, the program updates your web server with a list of folders. Your pages are maintained by these, which range from the wp-admin directory, which houses administrative files, to the wp-content
directory, which houses themes and plugins
WordPress also includes a .htaccess
file in addition to its core folders. It is, in essence, a configuration file that governs the operation of your server. We will provide you with information on this configuration file, including where to find it and how to make a new file from scratch.
In this blog, we’ll discuss how to locate and create a .htaccess WordPress file on cPanel and other web hosting. And also discuss the .htaccess file for WordPress basic and multisite websites.
What is the .htaccess file?
The .htaccess (hypertext access) is a critical WordPress core file used to enable or disable features of websites hosted on Apache.
The .htaccess files are also referred to as server configuration files located in your WordPress root directory. By default, WordPress uses the .htaccess files to manage redirects and permalink structures.

Many WordPress plugins also use .htaccess files to operate, including most security plugins and caching plugins. These plugins modify and rewrite the .htaccess files to perform their functions.
More advanced server configuration changes include the ability to:
- Set up redirects – you can set a 302 redirect to your temporary domain or a 301 redirect to move all HTTP traffic to your HTTPS site.
- Rewrite URL – create SEO-friendly URLs to improve search engine indexability and crawlability.
- Enable hotlink protection – the .htaccess file allows you to prevent hotlinking from your site and protect your bandwidth usage.
- Modify access restriction – deny specific IP addresses from your site, make a certain type of files inaccessible, or completely restrict access to your site.
- Serve custom error pages – customize the message that appears on your 404 error not found or 403 Forbidden pages.
- Password-protect directories – command every directory to require a valid user by setting up a password and creating a .htpasswd file.
Access this free .htaccess generator page to generate code snippets and set up more advanced rules on your site.
How to locate the .htaccess file
When you install WordPress on Apache Web Server, the .htaccess file is automatically added to your root directory, generally labeled as public_html or www. However, since the file is usually hidden, you will need to use the Show Hidden Files option to find it.
The following sections will walk you through the steps of locating your WordPress site’s .htaccess file in cPanel.
1. Access your siteground dashboard. Click on File Manager on your dashboard.

2. By default, the .htaccess file is not hidden in siteground hosting. Thus, simply click on your public_html directory and look for a file labeled as .htaccess.

3. Access the file and its content by right-clicking and selecting Edit.

Note: those steps depend on your hosting panel. Just find your .htaccess file from the hosting panel.
How to create a .htaccess file
There are a few instances where your WordPress installation will not include the .htaccess file by default. Alternatively, a broken plugin might corrupt this server configuration file and disrupt your site. In these cases, you will need to create a new file from your hosting control panel manually.
Siteground users will locate the New file button on the left sidebar menu on your File Manager > public_html folder.

Enter .htaccess as the file name, then insert the code below:

Code for basic WordPress Site
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Code for WordPress Multisite
– WordPress 3.5 or later –
If you activated Multisite on WordPress 3.5 or later, use one of these.
Subfolder Example:
# BEGIN WordPress Multisite
# Using subfolder network type: https://wordpress.org/support/article/htaccess/#multisite
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
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]
# END WordPress Multisite
Subdomain Example:
# BEGIN WordPress Multisite
# Using subdomain network type: https://wordpress.org/support/article/htaccess/#multisite
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
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]
# END WordPress Multisite
– WordPress 3.4 and below –
If you originally installed WordPress with 3.4 or older and activated Multisite then, you need to use one of these:
Subfolder Example:
# BEGIN WordPress Multisite
# Using subfolder network type: https://wordpress.org/support/article/htaccess/#multisite
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [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).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress Multisite
Subdomain Example:
# BEGIN WordPress Multisite
# Using subdomain network type: https://wordpress.org/support/article/htaccess/#multisite
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
# END WordPress Multisite
Once you’ve added the code, press Create to save your changes. Keep in mind that the code is universal for all WordPress sites. However, other content management systems (CMSs) will have different codes for their .htaccess files.
Aside from the method above, you can also use a text editor such as Notepad to create a .htaccess file, and then upload it to your web server using an FTP client.
Conclusion
A configuration document used in WordPress websites is the .htaccess
file. This file is crucial to maintaining the accessibility of your website because it controls the server’s operation.
A.htaccess file is included with every WordPress installation, and you may view it with an FTP program or your hosting control panel. Your web server will have several .htaccess files if you host several websites.
Utilizing your .htaccess files to their fullest potential will allow you to make different configuration adjustments for each directory. This entails putting a password on each directory, rerouting traffic from HTTP to HTTPS, and blacklisting or whitelisting particular IP addresses.
You may connect with us on Facebook and X. Also, check out our YouTube channel to view videos.
