Description: The .htaccess file is a server configuration file. It allows you to define rules for your server to follow for your website.
WordPress automatically stores some of its settings in .htaccess, and advanced users can edit the file manually to configure their website and solve problems.
The .htaccess file is located in your WordPress site’s root folder.
Before editing your .htaccess file, it is important to download a copy of it to your computer as a backup. You can use that file in case anything goes wrong.
Default code for WordPress:
# BEGIN WordPress
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]
# END WordPress
RewriteEngine On: Rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain. root.
RewriteRule ^index\.php$ - [L]:^index\.php$ - [L]prevents requests forindex.phpfrom being rewritten, to avoid an unnecessary file system check. If the request is forindex.phpthe directive does nothing-and stops processing rules[L].
RewriteCond %{REQUEST_FILENAME} !-d: Whether it is mandatory or not is really dependent on your filesystem and what you are trying to do. But generally, you don't normally want physical directories to be processed by the front controller.
RewriteCond %{REQUEST_FILENAME} !-f: The !-f condition is usually more important since you often don't want physical files to be processed by the front controller. This is required when you want to serve static resources (eg. CSS, JavaScript and images) from the same area on the filesystem.
