Default .htaccess file for your WordPress

Default .htaccess File for WordPress

The .htaccess file is a hidden configuration file used by the Apache web server. WordPress uses this file to manage permalinks and URL rewrites. If your .htaccess file gets corrupted or accidentally deleted, your WordPress pages may return 404 errors.

The Default WordPress .htaccess Code

Copy and paste the following code into your .htaccess file located in the root directory of your WordPress installation:

# BEGIN WordPress
<IfModule mod_rewrite.c>
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]
</IfModule>
# END WordPress

For WordPress Installed in a Subdirectory

If WordPress is installed in a subdirectory (e.g., /blog/), use this version:

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

For WordPress Multisite (Subfolder)

# BEGIN WordPress 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

How to Create or Edit the .htaccess File

  1. Log in to cPanel and open the File Manager.
  2. Navigate to the public_html directory (or your WordPress root).
  3. Click "Settings" in the top-right and check "Show Hidden Files".
  4. If .htaccess exists, right-click and select "Edit". If not, create a new file named .htaccess.
  5. Paste the appropriate code above and save.

Fixing Permalink Issues

If your permalinks are broken after restoring the .htaccess file:

  1. Go to WordPress Admin > Settings > Permalinks.
  2. Click "Save Changes" (even without changing anything). This regenerates the rewrite rules.

Security Tip

Set the correct permissions for your .htaccess file:

chmod 644 .htaccess

This ensures the file is readable by Apache but not writable by unauthorized users.

  • wordpress, htaccess, permalinks, apache, seo
  • 0 Корисниците го најдоа ова како корисно
Дали Ви помогна овој одговор?