How to Fix 301 Moved Permanently Error?
Before we study whole about the 301 Moved Permanently Error, let’s starts a small discussion upon the redirects.
Are you not familiar with the redirects? Do you ever feel like how to create a redirect in WordPress, why do you need, and when you should use redirects?
The 3xx HTTP Status Code Series
The 3xx HTTP Status Code series indicates that the client must take additional action to complete the request and access the desired resource. Mostly these status codes are used in URL redirection. The 301 redirects are considered best for upgrading users from HTTP to HTTPS.
What is a Redirect in WordPress?
A redirect is a way to send a quick message to your readers to tell them that the page they want to visit has moved, so their browser can automatically point them to the new page of your choice. There are the different type of redirects available, and some of them are 301, 302, and 307 redirects.
What is 301 Moved Permanently?
301 status code indicates that the URL of the requested resources has changed and a new URL is assigned, in the response. In short, it tells that the URL has Moved Permanently and it will pass the 90% of the Search Engine Link Juice to the new URL.
Where is the problem?
The problem is on the Server Side. As I told you, the 3xx series codes are considered to be redirection messages. Such status codes are generated in response when there is an additional action is required to complete the request on the active web server.
The 301 Moved Permanently code shows an issue on the actual web server hosting your website. Most of the web browsers are automatically detect the 301 Moved Permanently response code and process the redirection action automatically.
Let’s have a small example to understand how it occurs.
Suppose you are accessing a URL like http//:tech-banker.com, but the web server is configured to force redirection to a secure version using https. It informs the browser regarding redirecting the request from http://tech-banker.com to the secured https://tech-banker.com.
In most cases, the browser will automatically detect the 301 Moved Permanently response code after that it will read the new location URL and redirect the request to that new location.
Thus, if you attempt to go through http://tech-banker.com right now, you’ll automatically be redirected to the HTTPS version of the site: https://tech-banker.com.
Start With a Backup
Before moving, it is suggested to take a complete backup of your website. You can use any WordPress backup plugin to backup your site. You may use Backup Bank to backup your site. It is freely available on wordpress.org. With the help of Backup Bank, you can take backup manually even you can also schedule your site back up.
Diagnoses for 301 Moved Permanently Response Code
The 301 Moved Permanently indicates that the URL or resources you are trying to access are not valid and must be redirected to a new URL.
Here are some steps that may help you in troubleshooting this error.
Method 1) Check the Server Configuration Files
Apache or Nginx are the two most popular web servers. Your site is probably running on one of these web servers. Thus, the first step you can take to determine the cause of 301 response code is to check the configuration files for your web server.
If you are on Apache Web Server then, Look for a .htaccess file within the root directory of your website file system. You can find the file at /home//public_html/.htaccess . If you found the .htaccess file, open it in a text editor and look for RewriteXXX directives, which are part of the mod_rewrite module in Apache.
These directives define a text pattern that will match against the requested URL.
RewriteCond directives are used to perform the actual redirection of the request to the appropriate URL. If you find any strange RewriteCond or RewriteRule directives in the .htaccess file, try temporarily commenting them using the # character prefix and restarting your web server to see if the issue resolved or not.
You can also try deleting the .htaccess file and recreate it. It is quite easy to recreate a .htaccess file. Here are the steps:
1. Login to your WordPress admin and navigate to the Settings Menu.
2. Move to the Permalinks Menu and click on the Save Changes button.
This way, you have a new bug free .htaccess file. On the other hand, if your server is running on nginx then, you’ll need to look for an entirely different configuration file.
nginx.conf is the file and is located in: /usr/local/nginx/conf, /etc/nginx or /usr/local/etc/nginx
Once found, open nginx.conf in a text editor and look for the rewrite directives. Check for any abnormality and comment them out before restarting the server to see if the issue was fixed.
Method 2) Check the Logs
Logs provide the details about the health and status of all the server. They tell about the nature and the type of the error. They tell, on which file it is appearing, line number where it is appearing. By so, it becomes easy to detect and correct the error.
Method 3) Custom Code or Script File
It may be that your custom code is generating the error. Try to diagnose the issue by manually debugging your custom code. Remove the code snippet or the file and check the tab with the error.
Why do you need to use a 301 Moved Permanently?
Let’s take a look at why it is necessary to understand the use of 301 redirects. The reason to use 301 HTTP Status Code is you want your user to redirect to a new page when a page or post on your site has moved permanently.
Below are some points that will show you when you need to use a 301 redirect in WordPress.
1. When you plan to delete a post or page.
2. When you plan to change the permalinks of your post or page.
Now, the answer to why you need to create a 301 redirect is, it will not only save your website from showing the 404 Not Found message on your screen but also save it from degrading the site’s search engine ranking.
The 301 Moved Permanently error, tells search engines that the page you are trying to access has permanently moved to a new location.
It’s recommended to set up 301 redirects in WordPress when you change the URL (permalinks) of your posts and pages or move your website from one domain to another. The 301 redirects are considered best for upgrading users from HTTP to HTTPS.