Blog

Editing Your .htaccess File

In this doc, we will cover:

  • Editing your .htaccess file.
  • The code required by a WordPress installation.
  • The code required by a WordPress Multisite Network.

Editing Your .htaccess File

When editing your .htaccess file, you will have to access your site via FTP or File Transfer Protocol. There are a number of FTP clients to help you with this based on whether you are using Windows or Mac.

Windows FTP Clients

Mac FTP Clients

You will need some information from your web host to access FTP. Most of this information can be found at your hosts control panel.

  • FTP Host
  • FTP Port
  • FTP Username
  • FTP Password

Some FTP clients hide hidden files such as the .htaccess file by default. Because of this you will need to enable display of hidden files.

If FTP sounds too scary to you, it really isn’t. It just takes some getting used to. However, most hosts have cPanel which contains a File Manager. If you are not sure if your host has a control panel such as cPanel, you should contact them directly.

Backing Up Your .htaccess File

Before you go any further, it is highly recommended that you back your .htaccess file up so if needed, you can revert it to an earlier version. One of the things you can do is simply download the file to your computer using your FTP Client or cPanel File Manager. Another way is to backup your website using a plugin like Snapshot Pro if you already have an existing WordPress installation.

Code Required For Your WordPress Installation

Once you have backed up your site, you will want to login using your FTP client. From here, you will want to navigate to “/public_html/.htaccess”. At this point, your .htaccess file should be open. Add one of the code snippets below to the top of your file based on what kind of WordPress setup you have at the top of your .htaccess file.

Single WordPress Installation


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Multisite WordPress Installation

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]

NOTE: Pay close attention, if you use Sub Domains, you will need different code than if you are using Sub Directories.

Sub Directory Installation

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]

Sub Domain Installation

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]

Don’t forget to save and re upload the file when you are done.


Originally published on WPMU DEV and written by Alex Stine | Last updated: January 4, 2017