神刀安全网

Fixing the Too Many Redirects Error in WordPress

Your site goes down and all your browser tells you is there are too many redirects or that your site is in a loop. Such a mysterious sounding error can leave you scratching your head, but you can unfurrow your brow because there’s a straightforward fix.

This kind of error is known as a 310 error but can sometimes show up as a 404 “page not found” error. It means the browser you’re using doesn’t know where it’s supposed to go so it throws up its arms and gives up.

It’s not quite that dramatic, but the problem is that your browser can’t reach your site either because the address you entered points to too many places or the address isn’t pointing to the right place.

To fix the issue, all you need to do is adjust the URL settings for your site, but depending on the exact circumstance, the fix may require some fancy footwork.

Not to worry, because in this post we’ll look at what exactly this error means, how it happens and how to fix it by changing a couple settings or digging into a wee bit of code.

Mo’ Redirects, Mo’ Problems

When your site or network is setup properly, you can type in your site’s address into your browser and your site loads because your address is pointing directly to your WordPress site. Sometimes, if your address points to different locations in your settings and they aren’t an exact match, your browser doesn’t know which location is the right one. It tries to figure it out and when it can’t, it times out and gives you a “too many redirects” error message. This message means your site is pointing to more than one location.

On the other hand, your browser may say that your site is in a redirect loop. This means the address you entered is pointing to your WordPress site, but your site tells your browser to go to a different address instead. The browser is redirected to the other address, but then your browser is told to go back to your WordPress site.

Your browser keeps going back and forth like a great game of ping pong. It times out when, after a while, it can’t stop at just one site. In other words, the browser is caught in a loop.

Fixing the Too Many Redirects Error in WordPress
When there’s a conflict with your site’s address, browsers get stuck when trying to access your site.

Getting Caught in a Loop

Most of the time, these error messages happen because there’s a misconfiguration in your settings, but sometimes, it’s a bit more complicated than that.

You could be seeing these error messages if:

  • Your home and site URLS are different or incorrect
  • There are misconfigured plugins installed that redirect your site
  • There’s a mishap with custom changes to the .htaccess  file
  • A new site is created in your network with the same URL as a deleted site
  • You’re hosting multiple sites or networks on one IP address

These may all seem like innocent settings and clicks, but each of them can break your site and cause a redirect error. Fixing these probable causes is the next step toward getting your site back up and running.

Getting Out of the Loop

Taking a more in-depth look of each of these possible reasons for the redirect error can help you identify which one your site is experiencing. Once you apply the fix for it, your site should start displaying again. You can try out other solutions as well.

Home and Site URLs

The home URL is the address you want your visitors to enter into their browser to view your site. It’s also another name for the Site Address (URL) field under Settings > General for single installs of WordPress.

The site URL is where your site and its core files can be found. It’s also called the WordPress Address (URL) on the general settings page for single installs.

If these two URLs aren’t properly set or there’s a typo, then it could lead to a redirect error. Typically, the address for both of these are the same, but it’s not always the case. They should also not include a slash at the end and should be consistent in their structure.

Both URLs should also have http:// in front unless you have an SSL certificate installed. If this is the case, the URLs should have https:// in front.

If one of the addresses includes a www. at the beginning, the other should as well and vice versa. You shouldn’t end up with a home and site URL that look like this:

Fixing the Too Many Redirects Error in WordPress
If your WordPress and site addresses are different, it could be why there’s a redirect error.

If you can’t access the general settings page or you have a Multisite network, you can still change these URLs to make sure they are correct. Add the code below to your wp-config.php file to hardcode these values into your site or network:

These two lines should also be placed above the /* That's all, stop editing! Happy blogging. */ line.

Keep in mind that you should replace http://your-site.com with your actual URL. Also, if you have a single install, you won’t be able to change these addresses in your dashboard settings after adding these two lines.

Redirected Pages via Plugins

WordPress uses the wp_redirect () function for permalinks and some plugins and themes use it as well. This function lets the specifiedURL be directed to a page or post within your site. It can also be used to make 301 redirects. Once a redirect is set up, it changes the location where an address is pointed to a different destination.

A 301 redirect can be useful if you wanted visitors of an old post you wrote to be automatically redirected to a new, updated post on the same topic, for example, but there are other reasons why a redirect could be useful such as if you got a new domain name and wanted to switch out your current site’s domain for your new one.

If you tried to point a post, page or subsite in your network to one that already exists, visiting the page would result in a redirect error. The single URL would be attached to two pages and a browser wouldn’t know which page was the correct one. While WordPress won’t let you create duplicate links when you’re writing a post, it’s possible to accidentally create duplicate links if you were to use a plugin that creates 301 redirects for you.

While WordPress won’t let you create duplicate links when you’re writing a post, it’s possible to accidentally create duplicate links if you were to use a plugin that creates 301 redirects for you. This can also happen if you’re switching your pre-existing Multisite install from subdomains to subdirectories.

This can also happen if you’re switching your pre-existing Multisite install from subdomains to subdirectories. The subdomains you previously created would be switched from blog.your-site.com to your-site.com/blog and if there’s already a blog page under that directory, then a redirect error would ensue since two pages can’t share the same URL.

To solve this issue, deactivate any plugins you have installed that use the wp_redirect () function. If you’re not sure which of your plugins redirect URLs for you, then deactivate all your plugins.

Sign up for moreWordPress wisdom

Check to see if you can view your site. If you can, then one of your plugins is causing the error. If you deactivated all of them, you can reactivate your plugins one-by-one until your site causes the error again.

When you see the error, you can determine that the last plugin you activated is the culprit. Then, you can check your settings to be sure they’re correct. It’s also important to make sure you didn’t enter in the same redirect twice since this would cause the error to come up as well.

If changing the settings for the plugin doesn’t resolve the issue, you may need to try other fixes or if you’re sure it’s a plugin issue, you can contact the developer.

Restoring the .htaccess File

Remember when you made custom changes to your .htaccess file? If you can, then this may be causing the issue. Double check the file and see if you notice any duplicate redirects or any URLs that aren’t correct.

If you can’t spot anything, you can download a copy of your .htaccess file as a backup and upload a fresh copy without all your customizations. You can find out what the contents of your new file should be by visiting the WordPress Codex .htaccess page .

Upload the new copy to your site and try visiting the main page. If your site is displayed, then one of your custom changes was the culprit. Try adding them again, one-by-one, until your site results in a redirect error again and when it does, you can correct the last amendment.

Clear Your Cache and Cookies

Sometimes all it takes is clearing your browser’s cache and cookies. If you make a major change to your site, it may not be visible until you clean up. Since a static copy of your site is temporarily saved to your browser to load it quicker, it means that new changes may not be reflected until you tell your browser you want a new copy of your site saved.

To clear your browser’s cache and cookies, check out these documentation pages for the most popular browsers:

If you have a Multisite network and this worked for you, this may only offer a temporary solution. You may need to add code to your wp-config.php file or upgrade to a dedicated IP address. Read on for more details.

Upgrade to a Dedicated IP

Your domain name is a user-friendly way to get to your site. Your domain is connected to the IP address where your site is hosted.

When you enter your domain into your browser, it connects to your site’s IP address, then goes to your site from there. Typically, only one site is connected to a single IP address and this direct route could be broken if you host your site or network using shared hosting or you have installed multiple sites using one IP address on your VPS or dedicated server.

Since multiple sites would be sharing one IP address, your browser may not be sure which one is the one it’s supposed to visit. When you visit one of your sites for the first time, your browser would create a cookie for that site and include the IP address for your site.

At this point, if you were to visit another one of your sites using the same IP address, your browser would see the existing cookie for the IP, but notice the URL is different so it wouldn’t be able to issue the same cookie or create a new one. This means your browser wouldn’t be able to visit the site and you would see an error appear.

Upgrading to a dedicated IP address for each of your sites would effectively fix this issue, but there’s another method you could try before shelling out the cash.

Auto-Clear Browser Cookies

You could manually clear your browser’s cookies each time you visit one of your sites, but that can quickly become tedious. Your visitors would also have to do the same and that’s not a user-friendly fix.

Instead, developer Tom McFarlin suggests on his blog to add the following code to your wp-config.php file above the “happy blogging” line:

It should automatically clear your browser’s cookies so that it doesn’t have to be done manually every time you visit one of your sites.

Fixing Human Error

When you understand why a “too many redirects” or “redirect loop” error comes up, you can quickly fix it and get your site back up. It usually comes down to basic human error, but if that’s not the case, you now have the tools to fix it.

Have you come across a redirect error before? Were you able to resolve it? What did you try and what are your favorite tips and tricks to fix the issue? Feel free to share your experience in the comments below.

Sign up for more WordPress wisdom

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Fixing the Too Many Redirects Error in WordPress

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址