WordPress.org

Ready to get started?Download WordPress

Forums

Proper 301 Redirect in .htaccess (14 posts)

  1. Shyzer
    Member
    Posted 3 years ago #

    I've got a fairly old post that I want to redirect to a new page. Since it has a million linkbacks to it, I'm trying to manually set up a 301 redirect in .htaccess without using a plugin.

    Old post: http://www.heyitsfree.net/2006/10/03/birthday-freebies/
    New page: http://www.heyitsfree.net/birthday-freebies/

    Would I simply use this?
    Redirect 301 /2006/10/03/birthday-freebies/ http://www.heyitsfree.net/birthday-freebies/

    Or is there something I'm missing here?

  2. That syntax looks correct. Try it and see. If it doesn't work, make sure there are no blank lines at the beginning or end of your .htaccess file and check your host's documentation for their recommended Redirect syntax.

    http://www.isitebuild.com/301-redirect.htm

  3. Put that ABOVE the wordPress htaccess calls, by the way.

  4. Shyzer
    Member
    Posted 3 years ago #

    Thanks to both of you! I got the redirect up and running now without any problems.

  5. eluviis
    Member
    Posted 3 years ago #

    Oh cool. This just helped me too. :) I'm doing something similar.

    Hey, when I was going to write my redirects I saw some Apache code I didn't recognize, in the htaccess. My other htaccess files from other sites don't have this particular code. Can any of you guys tell me what it is and what it's for? This is how it looks:

    #Apache 1.3
    
    Options +Includes
    
    #AddHandler server-parsed .html
    
    XBitHack on

    I put all my redirects before that stuff, but I'm wondering if I need any of that. BTW, the old site is .HTML and I'm redirecting everything to a new WordPress-only site. Thanks, Danny

  6. eluviis - They have to do with server-side includes that may be in use on your site. If you're not using server-side includes (these are not as commonly used since the advent of languages like PHP) you can remove those lines, or comment them out by adding a # in front of the two lines that don't already have them. If you notice any adverse effects, you can put them back.

    http://httpd.apache.org/docs/2.0/howto/ssi.html

  7. rebelguru
    Member
    Posted 3 years ago #

    i can't get my redirects working properly at all, it's weird, only 1 url will redirect, everything after that won't. So if I add the other urls I want to redirect, I get a 500 server error.

    I'm trying to redirect all my old posts to the new url structure. An example would be redirecting: http://www.g33kpron.com/archives/2374 to http://www.g33kpron.com/twitter-infographic/

    Current htaccess:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^archives/2374$ http://www.g33kpron.com/twitter-infographic$ [R=301,L]
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    I'm so stumped.

  8. rebelguru - No, no, no. ;-)

    You are mixing up two different things, rewriting permalinks and redirecting your old URLs, and that's why it's going haywire. If you're using WordPress's pretty permalinks, you'll need the standard rewrite block for those, which looks like this:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    That is rewriting (not redirecting) WordPress's standard "ugly" permalinks - such as http://example.com/?p=N - to a nicer format, such as http://example.com/your-page-name/

    Above that block of code (as ipstenu said earlier) you can add the redirects, one line per URL. This is redirecting URLs from your old site to the new WordPress site.

    Example:

    Redirect 301 /archives/2374 http://www.g33kpron.com/twitter-infographic/

    Repeat, adding one line per old page/post.

  9. GRAQ
    Member
    Posted 3 years ago #

    There are plugins that handle redirection. e.g. http://wordpress.org/extend/plugins/redirection/

  10. eluviis
    Member
    Posted 3 years ago #

    @zoonini - When I migrated the site, the migration process eliminated that htaccess code I was concerned about. I have a backup, but it looks like I don't need it. Everything is working smoothly.

    @GRAQ - If I can do something while a avoiding a plug-in, I sure will. My 301 redirects worked like a charm.

    I've never needed rewrites. I have considering changing a site I have from /year/month/day/postname to /post_id/postname/ because I didn't want any more dating of my posts. If I decide to do that than I might consider rewrites.

    But, otherwise, I suppose can can simply change the permalink structure, make sure all my new urls are good to go and then add 301 redirects from my old permalinks. Not sure, but I don't see why not.

  11. rebelguru
    Member
    Posted 3 years ago #

    Thanks for clearing that up zoonini. I tried that but this time keep getting 500 errors now and takes the whole site down. Here's an example:

    Redirect 301 /archives/2374 http://www.g33kpron.com/twitter-infographic
    Redirect 301 /archives/2370 http://www.g33kpron.com/damn-ninjas-now-crashing-into-apple-stores
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
  12. I suggest contacting your host for support on this.

  13. rebelguru
    Member
    Posted 3 years ago #

    I got it working! I ended up having to use a rewrite afterall after playing with cpanel's redirect app. Here's my code:

    RewriteCond %{HTTP_HOST} ^g33kpron.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.g33kpron.com$
    RewriteRule ^archives\/2374$ "http\:\/\/www\.g33kpron\.com\/twitter\-infographic\/" [R=301,L]
    RewriteRule ^archives\/2370$ "http\:\/\/www\.g33kpron\.com\/damn\-ninjas\-now\-crashing\-into\-apple\-stores\/" [R=301,L]
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    Only difference is I had 135 redirects instead of the 2 I listed above. Works perfectly. Just thought I'd share the code.

  14. verilix
    Member
    Posted 3 years ago #

    Anyone know how I'd redirect the WordPress homepage [e.g, root], to another URL? For example: http://www.google.com/ - to http://www.google.com/home/ - leaving all the other URLs the same, but just 301ing the homepage?

Topic Closed

This topic has been closed to new replies.

About this Topic