Create a new htaccess file 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. # BEGIN WordPress: This line marks the beginning of the WordPress-specific configuration.
  2. <IfModule mod_rewrite.c>: This line checks if the Apache module mod_rewrite is available. If it is, the code inside this block will be executed.
  3. RewriteEngine On: This line enables the rewrite engine, which allows us to rewrite URLs.
  4. RewriteBase /: This line sets the base URL for the rewrite rules. In this case, it's set to the root of the website (/).
  5. RewriteCond %{REQUEST_FILENAME}!-f: This line checks if the requested URL is not a file. If it's not a file, the rule will be applied.
  6. RewriteRule ^(.*)$ $1/ [R=301,L]: This line adds a trailing slash to URLs that are missing one. The R=301 flag specifies that this is a permanent redirect, and the L flag specifies that this is the last rule to be applied.
  7. RewriteRule ^index\.php$ - [L]: This line specifies that the index.php file should not be rewritten.
  8. RewriteCond %{REQUEST_FILENAME}!-f: This line checks if the requested URL is not a file. If it's not a file, the rule will be applied.
  9. RewriteRule. /index.php [L]: This line rewrites all URLs that are not files to the index.php file. The L flag specifies that this is the last rule to be applied.
  10. </IfModule>: This line marks the end of the WordPress-specific configuration.
  11. # END WordPress: This line marks the end of the WordPress-specific configuration.

You can add more rules to this file as needed, but be careful not to overwrite the existing rules. It's also a good idea to backup your existing .htaccess file before making changes.

Note: If you're using a WordPress plugin that requires specific rewrite rules, you may need to add those rules to this file as well.