In WordPress, we have a configuration file named .htaccess. This file is used on web servers for running Apache Software and with this file, you can configure settings on your particular site.
What is .htaccess and why it is required?
It is a website file that controls the high-level configuration of the website and with this, we can make changes to our website configuration without editing the configuration files.
What is the need for a .htaccess file?
- Using this we can provide redirections for certain URLs.
- We can create error pages like 404 pages.
- This file will force our site to use HTTPS instead of HTTP.
- It can also prevent hotlinking.
WordPress can automatically create a .htaccess file but sometimes it is unable to do it due to some permission-related issue. For this issue, you can check out the points given below:
Step 1: Switch to your WordPress dashboard.
Step 2: Go to Settings >> Permalinks.
Step 3: Just scroll down and click on Save Changes.
Now WordPress will try to create a .htaccess file. If still, it’s giving you the error like “.htaccess file is not writable” then you need to create the .htaccess file manually.
How to Create the .htaccess file manually?
Step 1: Start this by logging into your hosting account’s control panel.
Step 2: Now open the File Manager and On the left-hand side, click on the public_html.
Step 3: In the toolbar at the top of your screen click on the +File icon.
Step 4: Now type in “.htaccess” into the New Filename and click on the Create New File.
Step 5: After that right-click to edit the new file.
Step 6: Add the given code:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
Step 7: After adding the code click on save.