SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot robcub's Avatar
    Join Date
    May 2008
    Location
    London, England
    Posts
    135
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Multiple redirects with .htaccess

    Hello,

    I have a WordPress site with a Permalink of /%category%/%postname% of over 350 blog posts and I want to change it to just postname /%postname%

    I have a few questions.

    Is there any quick way to do the redirects? So say I have a category of "fruits" could I put something in the htaccess that would redirect all posts that were originally site.com/fruits/postname to site.com/postname?

    And, secondly, it is bad to have too many redirects in an htaccess file? Would 350 slow down the site?

  2. #2
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,058
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    If the postname is staying the same, you'd just need one rule per category to do the redirects - i.e. /category/postname -> /postname - the rule would jsut throw away the category.

  3. #3
    SitePoint Zealot robcub's Avatar
    Join Date
    May 2008
    Location
    London, England
    Posts
    135
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank Tim. So redirects in .htaccess like this:

    redirect 301 /fruits/ http://www.yoursite.com/
    redirect 301 /vegetables/ http://www.yoursite.com/

    ... where "fruits" and "vegetables" are categories will redirect all the individual blog posts from category/blogpost to /blogpost.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Not quite, as that just redirects the category level but nothing under it. What you'd need to use instead is RedirectMatch, i.e.

    Code:
    /fruits/(.*) http://www.yoursite.com/$1
    /vegetables/(.*) http://www.yoursite.com/$1
    etc

    And of course make sure there aren't any posts called "fruits" or "vegetables" etc, as those would get redirected as well.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Zealot robcub's Avatar
    Join Date
    May 2008
    Location
    London, England
    Posts
    135
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Really appreciate you help of this one, Scallio and TimIgoe. I couldn't find this information out by Googling.

    Here's what I used and it worked:


    RedirectMatch /categoryname1/(.*) http://www.site.com/$1
    RedirectMatch /categoryname2/(.*) http://www.site.com/$1
    RedirectMatch /uncategorized/(.*) http://www.site.com/$1
    etc.

  6. #6
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,058
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    Excellent, glad it worked


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •