Default htaccess for WordPress

The htaccess file is required for our WordPress because it lets us create our site’s friendly URLs.

I often come across people who don’t realize how important it is until they open a URL on their website and get a 404. This is a configuration file for the web server (except for nginx, which doesn’t support it).

What WordPress’s htaccess does is redirect all URLs to index.php, letting WordPress decide what to do with each URL.

If you only want the htaccess code, I’ll leave it here and then keep telling you more.

Default htaccess

# 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

Default htaccess for a Multisite

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]

How to Regenerate the htaccess from wp-admin

Many people don’t know that from the WordPress admin panel we can generate the default htaccess file in just a few clicks. Here are the steps:

  • Log in to wp-admin
  • Go to Settings and open Permalinks
  • Click “Save Changes” without changing anything.

Done, our URLs work again and we have our htaccess regenerated.

Why Does .htaccess Start With a Dot?

This is because, on UNIX systems, such files are considered hidden, and since it is a web server configuration file, it’s better that only someone with the right knowledge sees it.

Surely this has happened to more than one of you: in your control panel, you had to enable show hidden files to be able to see it from the cPanel/Plesk/etc. file manager.