Create new htaccess for wordpress

Here is an example of a basic .htaccess file for a WordPress website:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Add a trailing slash to URLs that are missing one
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^(.*)$ $1/ [R=301,L]

# Rewrite rules for WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule. /index.php [L]

</IfModule>

# END WordPress

Let me explain what each line does:

  1. RewriteEngine On: Enables the Rewrite engine, which allows us to rewrite URLs.
  2. RewriteBase /: Sets the base URL for the rewrite rules.
  3. RewriteCond %{REQUEST_FILENAME}!-f: Checks if the requested URL is not a file.
  4. RewriteRule ^(.*)$ $1/ [R=301,L]: If the URL is not a file, adds a trailing slash to the URL and redirects the request to the same URL with the trailing slash. This is useful for SEO purposes.
  5. RewriteRule ^index\.php$ - [L]: Excludes the index.php file from being rewritten.
  6. RewriteCond %{REQUEST_FILENAME}!-f: Checks if the requested URL is not a file.
  7. RewriteRule. /index.php [L]: If the URL is not a file, rewrites the request to the index.php file, which is the entry point for WordPress.

Note that this is just a basic example, and you may need to customize the .htaccess file for your specific WordPress installation. For example, you may need to add additional rewrite rules for specific plugins or themes.

Also, if you're using a WordPress multisite installation, you'll need to add additional rewrite rules to handle the multisite functionality.

Before making any changes to your .htaccess file, make sure to backup your existing file and test the changes in a staging environment before applying them to your live site.

It's also important to note that the .htaccess file is specific to Apache web servers, if you're using a different web server, you may need to use a different configuration file.