WP Plugin to automatically create 301s?

18 replies
Hi there

I wasn't sure if this should go into the "programming" part of the forum, because technically it's not really about programming, but if it should, apologies to the mods for putting it in the wrong place.

Anyway, my question is, is there a WordPress plugin that can create a 301 redirect automatically if someone visits the site via an old link to a non existent page? So rather than the person getting a 404 page, they are just automatically redirected to the URL that you assign as being the "standard" URL to redirect to....most likely your homepage. Basically the assumption is that we can't keep track of all the old links the site has had, so rather than monitor the 404 logs, and retrospectively enter in 301s, is there a way for WordPress to proactively create the 301s AS the user is trying to visit the defunct page?

Any input on this would be much appreciated!
#301s #automatically #create #plugin
  • {{ DiscussionBoard.errors[4364401].message }}
    • Profile picture of the author bank1010
      thanks ... very good to know
      {{ DiscussionBoard.errors[4364714].message }}
  • Profile picture of the author Adaptise
    Thanks for the quick response Brian.

    I had a look at Redirection - it's definitely an awesome plugin, but I don't think it's quite what I'm looking for - this one you still have to manually configure each 404 to a 301 right? It doesn't automatically step in if a 404 occurs, it only logs it, and then AFTERWARDS you can setup a 301 for the 404s that it logged.....

    ....or did I just not read it's features correctly?

    Oh and I am aware it can create 301s automatically if a post URL changes, however I'm thinking more along the lines where external links have been pointing to a URL that was never part of the Wordpress install (ie in a previous life the domain was in plain HTML), so obviously there is no "record" of the old URL.....
    {{ DiscussionBoard.errors[4364452].message }}
  • Profile picture of the author Rus Sells
    Are you looking at something that does this dynamically on the fly? If so, I can't think of anything that does this.
    {{ DiscussionBoard.errors[4364525].message }}
  • Profile picture of the author Adaptise
    Hi Rus

    Yes, that's exactly what I'm thinking. Is it even possible?
    {{ DiscussionBoard.errors[4364535].message }}
  • Profile picture of the author Abledragon
    Whether you do it via a plugin or in your .htaccess file, you will need to know the old URL in order to have it re-directed if the old URL is not on your site.

    Redirection (or any other plugin) will only know about URLs in the current site.

    Cheers,

    Martin.
    Signature
    WealthyDragon - Earning My Living Online
    {{ DiscussionBoard.errors[4364610].message }}
  • Profile picture of the author Adaptise
    hmm. Is there a way to programatically tell WordPress that if it's about to serve up a 404 page, to redirect the user then?

    The issue is that we have no idea what a lot of the old URLs are, so we want to be proactive, and try and "stomp them out" without having to just monitor error logs over a few months.
    {{ DiscussionBoard.errors[4364629].message }}
  • Profile picture of the author diapteg
    How to Redirect a Web Page Using a 301 Redirect

    You've just redesigned some pages of your web site. The
    pages have high search engine rankings that you don't want
    to lose. How can you safely redirect web site traffic from
    your old pages to the new pages without losing your
    rankings? You can do this by using a " 301 redirect "

    What is 301 redirect?

    301 redirect is the best method to preserve your current
    search engine rankings when redirecting web pages or a web
    site. The code "301" is interpreted as "moved permanently".
    After the code, the URL of the missing or renamed page is
    noted, followed by a space, then followed by the new
    location or file name. You implement the 301 redirect by
    creating a .htaccess file.

    What is a .htaccess file?

    When a visitor/spider requests a web page, your web server
    checks for a .htaccess file. The .htaccess file contains
    specific instructions for certain requests, including
    security, redirection issues and how to handle certain
    errors.

    How to implement the 301 Redirect

    1. To create a .htaccess file, open notepad, name and save
    the file as .htaccess (there is no extension).

    2. If you already have a .htaccess file on your server,
    download it to your desktop for editing.

    3. Place this code in your .htaccess file:

    redirect 301 /old/old.htm http://www.you.com/new.htm

    4. If the .htaccess file already has lines of code in it,
    skip a line, then add the above code.

    5. Save the .htaccess file

    6. Upload this file to the root folder of your server.

    7. Test it by typing in the old address to the page you've
    changed. You should be immediately taken to the new
    location.

    Notes: Don't add "http://www" to the first part of the
    statement - place the path from the top level of your site
    to the page. Also ensure that you leave a single space
    between these elements:

    redirect 301 (the instruction that the page has moved)

    /old/old.htm (the original folder path and file name)

    http://www.you.com/new.htm (new path and file name)

    When the search engines spider your site again they will
    follow the rule you have created in your .htaccess file.
    The search engine spider doesn't actually read the
    .htaccess file, but recognizes the response from the
    server as valid.

    During the next update, the old file name and path will be
    dropped and replaced with the new one. Sometimes you may
    see alternating old/new file names during the transition
    period, plus some fluctuations in rankings. According to
    Google it will take 6-8 weeks to see the changes reflected
    on your pages.

    Other ways to implement the 301 redirect:

    1. To redirect ALL files on your domain use this in your
    .htaccess file if you are on a unix web server:

    redirectMatch 301 ^(.*)$ http://www.domain.com
    redirectMatch permanent ^(.*)$ http://www.domain.com

    You can also use one of these in your .htaccess file:

    redirect 301 /index.html http://www.domain.com/index.html
    redirect permanent /index.html http://www.domain.com/index.html
    redirectpermanent /index.html http://www.domain.com/index.html

    This will redirect "index.html" to another domain using a
    301-Moved permanently redirect.

    2. If you need to redirect http://mysite.com to
    http://www.mysite.com and you've got mod_rewrite enabled on
    your server you can put this in your .htaccess file:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example\.com
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

    or this:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

    Tip: Use your full URL (ie http://www.domain.com) when
    obtaining incoming links to your site. Also use your full
    URL for the internal linking of your site.

    3. If you want to redirect your .htm pages to .php pages
    andd you've got mod_rewrite enabled on your server you can
    put this in your .htaccess file:

    RewriteEngine on
    RewriteBase /
    RewriteRule (.*).htm$ /$1.php

    4. If you wish to redirect your .html or .htm pages to
    .shtml pages because you are using Server Side Includes
    (SSI) add this code to your .htaccess file:

    AddType text/html .shtml
    AddHandler server-parsed .shtml .html .htm
    Options Indexes FollowSymLinks Includes
    DirectoryIndex index.shtml index.html

    Frequently Asked Question:
    What's the difference in using a 301 redirect versus a meta redirect?

    Meta Redirect
    To send someone to a new page (or site) put this in the head of your
    document:

    <meta http-equiv="refresh" content="10;
    url=http://mynewsite.com/">

    Content="10; tells the browser to wait 10 seconds before
    transfer, choose however long you would like, you can even
    choose 0 to give a smoother transition, but some (really
    old) browsers aren't capable of using this so I'd suggest
    putting a link on that page to your new site for them.

    With a meta redirect the page with the redirect issues a
    200 OK status and some other mechanism moves the browser
    over to the new URL. With a 200 OK on both pages, the
    search engine wants to index both the start page and the
    target page - and that is a known spam method (set up
    10,000 domains full of keywords for the search engines to
    index then meta redirect the "real visitor" after 0 or 1
    seconds to the "real site" ) so using it gets you
    penalized.

    The 301 redirect simply issues a Permanently Moved message
    in the HTTP header which tells the search engine to only
    index the target URL.

    Conclusion: The safest way to redirect old web pages to the
    new pages or old web site to the new web site and keep the
    same search engine rankings is to use the 301 redirect. It
    will also pass on the page rank from your old site to your
    new site.
    {{ DiscussionBoard.errors[4364707].message }}
    • Profile picture of the author Adaptise
      Originally Posted by diapteg View Post


      What is 301 redirect?

      301 redirect is the best method to preserve your current
      search engi....
      Thanks, but something tells me you didn't post this to be helpful.

      I wasn't asking for the basics of 301s.
      {{ DiscussionBoard.errors[4364736].message }}
  • Profile picture of the author cd4337
    I use this "Smart 404" for Wordpress


    "Instead of quickly giving up when a visitor reaches content that doesn't exist, make an effort to guess what they were after in the first place. This plugin will perform a search of your posts, pages, tags and categories, using keywords from the requested URL. If there's a match, redirect to that content instead of showing the error. If there's more than one match, the 404 template can use some template tags to provide a list of suggestions to the visitor."
    {{ DiscussionBoard.errors[4364745].message }}
  • Profile picture of the author Adaptise
    Yeah I've looked at that plugin as well. It still doesn't fit what I'm looking for.

    It seems all the plugins out there are all retrospective. At this stage I'll presume that's because there is no way to create some sort of redirect on the fly, which sucks, because I think it would be an incredibly useful plugin to have....
    {{ DiscussionBoard.errors[4364762].message }}
    • Profile picture of the author cd4337
      Originally Posted by Adaptise View Post

      Yeah I've looked at that plugin as well. It still doesn't fit what I'm looking for.

      It seems all the plugins out there are all retrospective. At this stage I'll presume that's because there is no way to create some sort of redirect on the fly, which sucks, because I think it would be an incredibly useful plugin to have....
      You might want to do a search for a plugin that rewrites the header code of a particular page (which is another way of doing a 301) Most plugins just edit the ht file.

      Just an idea
      {{ DiscussionBoard.errors[4364922].message }}
  • Profile picture of the author Adaptise
    Someone just referred me to Link Juice Keeper. It's a little dated, so it looks like it may not be compatible with WP 3.0, but looking at the coding, it's pretty small, so I'm guessing it wouldn't take much to update this. Wishing I could code....
    {{ DiscussionBoard.errors[4373091].message }}
    • Profile picture of the author SteveJohnson
      Originally Posted by Adaptise View Post

      Someone just referred me to Link Juice Keeper. It's a little dated, so it looks like it may not be compatible with WP 3.0, but looking at the coding, it's pretty small, so I'm guessing it wouldn't take much to update this. Wishing I could code....
      There's nothing in that plugin that's incompatible with 3.xx, if you really want to use it.

      You should ask yourself, though, if this is the wisest course of action. 404 status codes exist for a reason - to let the browser and the user know that the URL is not good. Keep in mind that Google is a 'user' also - its spiders receive the same status codes that a browser gets.

      A 301 Moved Permanently status is not what you want to tell Google about those old links. When the big G follows a bunch of old, out-dated links into your site and gets told that the content of all of them has been moved to the index page, do you not think that will throw a little bit of a red flag?
      Signature

      The 2nd Amendment, 1789 - The Original Homeland Security.

      Gun control means never having to say, "I missed you."

      {{ DiscussionBoard.errors[4373369].message }}
      • Profile picture of the author Adaptise
        Originally Posted by SteveJohnson View Post

        There's nothing in that plugin that's incompatible with 3.xx, if you really want to use it.

        You should ask yourself, though, if this is the wisest course of action. 404 status codes exist for a reason - to let the browser and the user know that the URL is not good. Keep in mind that Google is a 'user' also - its spiders receive the same status codes that a browser gets.

        A 301 Moved Permanently status is not what you want to tell Google about those old links. When the big G follows a bunch of old, out-dated links into your site and gets told that the content of all of them has been moved to the index page, do you not think that will throw a little bit of a red flag?
        Very good point Steve. Surely it's slightly more helpful than leaving people stranded on a 404 page though. The number of times I've hit even "decent" 404 pages with a search bar or suggestions of what I "might" have been trying to look for is unreal, yet every single time it was "off the mark".

        Then again, if I was the average user I'd probably be pretty annoyed if it redirected immediately, because I'd never know if the redirect was some sort of scam or something.
        Hmm, I guess nothing replaces good 'ol hard work in fixing all the broken links by approaching each and every site that was linking to the old pages....
        {{ DiscussionBoard.errors[4373443].message }}
        • Profile picture of the author SteveJohnson
          Originally Posted by Adaptise View Post

          Very good point Steve. Surely it's slightly more helpful than leaving people stranded on a 404 page though. The number of times I've hit even "decent" 404 pages with a search bar or suggestions of what I "might" have been trying to look for is unreal, yet every single time it was "off the mark".

          Then again, if I was the average user I'd probably be pretty annoyed if it redirected immediately, because I'd never know if the redirect was some sort of scam or something.
          Hmm, I guess nothing replaces good 'ol hard work in fixing all the broken links by approaching each and every site that was linking to the old pages....
          I know from trying - it's really hard to build a 404 script that's telepathic...you just have to do the best you can and know that it's better than nothing.

          As far as getting people to change links - good luck. THAT is precisely what a 301 is for, assuming that the content has actually moved, that is. If you have replacement content, put a 301 redirect in your htaccess file for the bad URL and be done with it.
          Signature

          The 2nd Amendment, 1789 - The Original Homeland Security.

          Gun control means never having to say, "I missed you."

          {{ DiscussionBoard.errors[4373737].message }}
          • Profile picture of the author Gabby12
            To redirect pages that no longer exist replace 404.php code in the theme editor with:
            <?php
            header("HTTP/1.1 301 Moved Permanently");
            header("Location: ".get_bloginfo('url'));
            exit();
            ?>
            very easy and works well.
            Signature

            SEO Content Writing
            Quality Content Writing Service

            {{ DiscussionBoard.errors[4373922].message }}
            • Profile picture of the author Adaptise
              Originally Posted by Gabby12 View Post

              To redirect pages that no longer exist replace 404.php code in the theme editor with:
              <?php
              header("HTTP/1.1 301 Moved Permanently");
              header("Location: ".get_bloginfo('url'));
              exit();
              ?>
              very easy and works well.
              Very nice and simple solution, thanks Gabby.
              {{ DiscussionBoard.errors[4374035].message }}

Trending Topics