The MU forums have moved to WordPress.org

SEO & .htaccess 301 redirect for individual pages (15 posts)

  1. matt123
    Member
    Posted 14 years ago #

    After getting onto the first page of google for a keyword phrase, and having it index the second page related to the term I am motivated to redo my permalinks.

    I'm trying to figure out the code I need in my .htaccess page to redirect from one page to another.

    To better highlight this I'll use an example:

    Current location of recent blog posts:
    http://mywebsite.com/blog-posts

    I want to change it to:
    http://mywebsite.com/keyword-blog-posts

    I have been unable to locate the code I need to do this. If someone could provide some links, answers or input that would be much appreciated!

  2. lunabyte
    Member
    Posted 14 years ago #

    Skip htaccess, and use PHP instead.

    A couple of lines in your main (as in site root, not theme) index.php file, before it includes the blog header, will fix it and eat a little less than htaccess.

    You'll have to analyze the request uri, and check against the http host (don't want to screw up someone else's blog), but once that's good you can do a string replace, and then do a 301 header redirect. You would be looking at 4 or 5 lines at most, probably less.

    Your if statement will take care of the checks for the host and uri, and then from there you'll have to do the string replace (which can be done within the header redirect, then you'll need an exit call, so nothing else is processed afterwards.

  3. matt123
    Member
    Posted 14 years ago #

    Not that php savy. Any links to information on how to set this up?

  4. lunabyte
    Member
    Posted 14 years ago #

  5. matt123
    Member
    Posted 14 years ago #

    thanks! I'll check it out. no time like the present to learn. ended up going with an .htaccess redirect. From an SEO standpoint is it better to do it via php?

  6. lunabyte
    Member
    Posted 14 years ago #

    Sending a 301 is sending a 301. PHP, HTML, htaccess, whatever.

    The question comes down to resources, and what processing specifically eats less.

    Using htaccess can work in small doses, but extended entries can lead to much bloat and unneeded processing by apache (before loading the site).

    On the other hand, you can go with PHP which can turn what would be long in htaccess into something short.

    While you can do pattern matching in htaccess, where I personally see an advantage with PHP in something like this is arrays.

    Right now, you only want to turn from one thing to another.

    At some point, you may want or need to turn 3 things into 3 more which gives a total of 4. At that point, arrays come in handy because with only adding maybe 2 more lines (and only if you define your arrays as variables outside the checks in place), you can now do what would take at least 4 different rewrite rules to accomplish.

    So again, it comes down to how efficient one is vs the other. Which, is why you would put the PHP stuff into the root index, before WP is fired up.

  7. deltakid
    Member
    Posted 14 years ago #

    as lunabyte said:

    if ($_SERVER['SERVER_NAME'] == "whatever.youwant.com") {
    header("Location: http://wickiwacka.com/wuhu/",TRUE,301);
    die();
    }

  8. MrBrian
    Member
    Posted 14 years ago #

    Just don't do a 301 redirect using a meta refresh tag in HTML if you are focused on SEO. All the other methods are fine and work the same.

  9. jamescollins
    Member
    Posted 14 years ago #

    I would personally install the Redirection Plugin and define all your redirects in there.

    It's a lot easier than having to modify a PHP file every time you want to add a redirect.

  10. lunabyte
    Member
    Posted 14 years ago #

    It also uses more overhead, as it has to load most of wordpress first.

    Why waste all of that, especially in an MU environment?

  11. jamescollins
    Member
    Posted 14 years ago #

    Yes, that is also a good point lunabyte.

    If it's going to be a fairly static list of URL redirects, then the index.php solution would be better.

    However if multiple blogs will have their own URL redirects then the redirection plugin could be a good option.

    I guess it comes down to a trade off between convenience and performance.

  12. lunabyte
    Member
    Posted 14 years ago #

    Well, that was the original implication. For individual pages, it might be a better thing, because who wants to edit a file any time a user wants a redirect.

  13. deltakid
    Member
    Posted 14 years ago #

    The php header 301 redirect that I posted has the same seo benefits as a htaccess redirect right? This is just the first time that I don't do it with htaccess.

  14. lunabyte
    Member
    Posted 14 years ago #

    "Sending a 301 is sending a 301. PHP, HTML, htaccess, whatever."

  15. deltakid
    Member
    Posted 14 years ago #

    thx lunabyte

About this Topic

  • Started 14 years ago by matt123
  • Latest reply from deltakid