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:

  • http://example.com/
  • http://www.example.com/
  • http://example.com/index.php
  • http://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 URL Redirection, 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.

Tags: , , ,

24 Responses to “Turn Off WordPress Homepage URL Redirection”

  • On May 4, 2009 at 8:10 am,stratosg wrote:

    I hadn’t looked into it but i was wondering if this can be done at all. Although you have to be very careful when doing it since duplicate content is not generally a good idea. Nice to see you back ;)

  • On May 5, 2009 at 12:33 am,Harsh Agrawal wrote:

    I still prefer Index.html method to be the best and handy

  • On May 7, 2009 at 2:29 am,Ajith wrote:

    Hey welcome back. Where have you been?

    Thanks for this little tip on WP URL redirection

  • On August 5, 2009 at 5:19 pm,Christian wrote:

    Thank you… Didn’t even know there was a plugin yet… Love the idea of not needing to alter existing php

  • On October 16, 2009 at 3:45 am,Steve @ Find Retro Shower Curtain wrote:

    I agree, I don’t like altering .php files. I have done it but I’m never quite sure I’m not screwing something up in the process. Come to think of it, it caused me to delete and reload themes a few times. Thanks for the tip on the plugin. It will come in handy.

  • On October 28, 2009 at 2:59 pm,Dennis Edell wrote:

    Anyone home?

  • On November 3, 2009 at 9:27 pm,laura wrote:

    hi frien. how do you think about the pretty link. Its a redirection used to create redirection. are you think it will droped our web from search engine?

  • On February 5, 2010 at 10:25 am,Ryan wrote:

    Thank you for this. One Google search and I got my answer!

  • On February 5, 2010 at 3:09 pm,Bnpositive wrote:

    You can also use the All-In-One SEO plug-in which turns this function without editing the PHP yourself. I’m a big supporter, fan and friend of Mark Jaquith’s work, but this plug-in provides a lot more features as well if you’re going to install a plug-in.

  • On February 28, 2010 at 9:17 am,Brian D. Hawkins wrote:

    I guess I prefer the ‘extra work’ method. I use a sub-domain and match the headers to function site wide. Turning off the canonical URL redirection seems dangerous but I can see why some would go that route.

  • On May 27, 2010 at 12:38 pm,em wrote:

    I know I sound like a numpty but were do I put the plugin file?! I’ve downloaded ‘disable-canonical-redirects.php’ but don’t know were to upload it now?

  • On August 6, 2010 at 11:43 am,Webvet wrote:

    One main reason to turn this off in WP is for a very simple fact… and it relates to SEO; and take it from me, I have a been a full-time web developer for 12 years. The way WP wrote the redirect is bad. If you submit your site to Google, or it just finds it as www.yourdomain.com, and the WP redirect is set to yourdomain.com – Google will see a 301 message for www, but instead of following it, the bot will stop dead. So the bot never actually indexes any of your content! Yahoo.com bot does the same. So, you can either worry about the negligible issue of having duplicate content indexed, or settle with no content index at all… I choose multiple content.

  • On August 14, 2010 at 5:48 pm,Career Outlook wrote:

    Very useful tutorial and I didn’t know that wordpress has a automatic redirection system. It could also cause the duplicate content issue within a site.

  • On October 6, 2010 at 10:54 pm,Ajay wrote:

    Just found out that if you are using redirect plugin you need to go to redirection > groups > and remove the latest redirection as automatically setup.
    Wordpress 3.0 seems to stuff this up with the redirection plugin.

  • On December 24, 2010 at 11:45 pm,pageblip wrote:

    is it possible to rename index.php?
    i face this problem for some time. but still can’t get any answer on the internet. :(

  • On January 28, 2011 at 11:33 pm,Abonk wrote:

    I have problem with cononical url, i was disabled the canonical url, and setting my .htaccess to redirect my blog from without www to using www, after that i can’t login to my admin page, my password was wrong..
    if i using without www i can login. any solution ?

    thanks

  • On January 29, 2011 at 6:43 pm,Renee wrote:

    I tried the solutions mentioned here on my WP 3.0.4 install. They did not help. What did was temporarily commenting out this line on \wp-includes\canonical.php –
    add_action(‘template_redirect’, ‘redirect_canonical’);

    I will comment it back in when the site is ready to go.

  • On February 5, 2011 at 12:49 pm,Sebastian @ Dinosaur Games wrote:

    Finding this article two months back would have saved me loads of time…
    I installed a new wordpress site and had big problems because I had put in a single HTML site for the first time in conjunction with the wordpress installation. It always redirected from sites to other sites with no apparant reason and I had no idea how to fix it x_x

    Now I’ll know where to look at if I should run into that again. Thanks.

  • On February 12, 2011 at 7:12 pm,jodi wrote:

    i tried what renee did and it works fine for the index.php page, however, when i click on the dummy ‘about’ page in the default template, it jumps back to the live index.html page – am i missing something obvious? thanks

  • On February 13, 2011 at 3:43 pm,jodi wrote:

    hi again

    fixed!!! mayur told me to change the permalink setting to month/date and it’s working now :)

  • On February 16, 2011 at 10:52 am,Harry Rate wrote:

    @Webvet.

    Sure it may be simpler to have multiple content, but it really does hurt your SEO.

    I wasn’t aware of the 301 problem, so should investigate. But could this be sorted out by setting the preferred domain in webmaster tools?

  • On March 23, 2011 at 4:53 am,Goran wrote:

    After 3 hours of work and searching for a solution that would solve my redirect problem, I have finally fount this website and I would like to thank tha author thousend times for this post.

  • On September 14, 2011 at 10:58 am,dub2dub wrote:

    I set up a new installation of WordPress in my addon domain’s root directory. I’ve created the webiste and everything. When I type in the url of my website, for example: http://example.com the site goes to a “Not Found” page, but my site is showing and if I click the “home” tab on the site, it shows my homepage correctly. Why isn’t my correct homepage showing when I type in my URL? Can someone please help me.

Trackbacks

Wanna run a Wordpress Network on multiple ports? | WebXL Consulting LLC

Trackback URL for this entry:
http://www.velvetblues.com/web-development-blog/turn-off-wordpress-homepage-url-redirection/trackback/

Leave a Reply

Want us to work on your project?

Contact us today for a quote. Click here to submit details regarding your project.

If you are making a general inquiry, send an email to info@velvetblues.com