WordPress.org

Ready to get started?Download WordPress

Forums

Simple 301 Redirects
I killed canonical redirection, which killed 301 redirection without "www." (2 posts)

  1. WaitWhereAmI
    Member
    Posted 1 year ago #

    Here's a fun one!

    WordPress was "guessing" redirects for nonexistent URLs and pulling up some pages and posts we didn't really want the public stumbling upon. e.g. "mysite.com/pro" would go right to "www.mysite.com/products". Which is fine in that case, but also resulted in some unwanted page redirections. I dropped this code into my functions.php to put an end to that:

    add_filter('redirect_canonical', 'no_redirect_on_404');
    function no_redirect_on_404($redirect_url)
    {
        if (is_404()) {
            return false;
        }
        return $redirect_url;
    }

    The only problem is that it interferes with your plugin. Urls that do not contain "www" in front of them do not redirect now, they 404. I am concerned about SEO implications and the fact that people are likely to skip typing "www" when trying to reach those urls.

    Is there any middle ground I can find to put an end to canonical redirection "guessing" without screwing up 301 redirection for all urls typed without "www"?

    http://wordpress.org/extend/plugins/simple-301-redirects/

  2. scottnelle
    Member
    Plugin Author

    Posted 1 year ago #

    This plugin isn't set up to handle www redirections. I generally advise people to set up a domain-level redirect to add (or remove, if you prefer) www in requests using .htaccess. Your web host can help you implement that.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic