Turn Off WordPress Homepage URL Redirection

If you are integrating WordPress into a preexisting site that already has its own homepage, or if you are developing a new WordPress website that is hidden behind a Coming Soon page, you will run into one frustrating problem. If you try to access the WordPress installation by visiting the index.php file, you won’t be able to see it. Instead, WordPress will automatically redirect you from the index.php page to the blog address url, as defined in your WordPress site settings.

There are, of course, several ways to get around this problem. Two common ways include:

  1. developing the WordPress site in its own directory
  2. integrating the preexisting site or coming soon page within the WordPress site

Unfortunately, these methods can result in quite a bit of extra work. Fortunately, it is easy to stop WordPress’ automatic redirects. But first, it is a good idea to know why WordPress employs these redirects.

Why WordPress Has Automatic URL Redirects

A page on any website, WordPress or not, can be accessed by multiple urls. For example, you can typically visit the home page of a WordPress web site by all of the following urls:

  • //example.com/
  • //www.example.com/
  • //example.com/index.php
  • //www.example.com/index.php

The problem with allowing all of these ways to access a single page is that it can potentially hurt your website’s overall search engine optimization (SEO). Having multiple urls for a page means that search engines could index duplicate copies. So WordPress fixes this problem by employing automatic redirects known as Canonical URLRedirection, which only enables one url per page.

How To Turn Off Canonical URL Redirection

To turn off Canonical URL Redirection, you can add the following code to your theme’s functions.php file.

remove_filter('template_redirect','redirect_canonical');

Not comfortable altering your theme files? WP developer Mark Jaquith has placed this code in his Disable Canonical URL Redirection plugin.

 

To learn more about the introduction of Canonical URLs, see Migrating Plugins and Themes to 2.3 in the WordPress Codex.

相关推荐

暂无评论

微信扫一扫,分享到朋友圈

Turn Off WordPress Homepage URL Redirection