The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to setup 301 redirects for specific urls in a .htaccess file

Discussion in 'General Discussion' started by godbar, Sep 3, 2012.

  1. godbar

    godbar Registered

    Joined:
    Sep 3, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I'm currently tearing my hair out over this. I have around 900 urls which need specific 301 redirects, for example

    old_url.php is now new-url.html

    Can someone please tell me the correct format/syntax to use when inserting a 301 redirect manually into a .htaccess file on a server using cPanel?

    I've spent about a week handcrafting these in a txt document after spending hours grilling the support staff at bluehost on the correct syntax but when I insert these lines of code into my .htaccess file I get server 500 errors so I've clearly got the syntax and placement of the redirects wrong. Here is how my 900 lines of code look.

    Redirect 301 /user.php?op=login&enable_back= http://www.loopgalaxy.com/my-account

    I've spent hours looking for forum posts that might solve this but they are a few years old and I guess things have changed. My other concern now is that even if I find some syntax that works it's not going to be easy to
    edit my code to what it needs to be. I can't face manually editing all 900 of these again :(

    Any advice is greatly appreciated.:p
     
  2. pwhjenny

    pwhjenny Well-Known Member

    Joined:
    Aug 31, 2012
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    Root Administrator
    Hello,

    You can use following code to redirect URL using .htaccess file .

    To redirect certain pages
    Code:
    Redirect 301 /oldpage.html http://www.yourdomain.com/newpage.html
     Redirect 301 /oldpage2.html http://www.yourdomain.com/newpage2.html
    To redirect entire website
    Code:
    Redirect 301 / http://www.new-site.com/
     
  3. godbar

    godbar Registered

    Joined:
    Sep 3, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hi pwhjenny,

    Yes that first is the exact code I used but when I insert that into my .htaccess file and try to view the site I get a 500 internal server error.

    I should mention that my site is a wordpress site in the root of my domain. The existing .htaccess file contains this:

    # 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

    I have tried pasting the redirect codes above this wordpress code but again it gives me the server error.
     
  4. godbar

    godbar Registered

    Joined:
    Sep 3, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    After struggling with this all day I luckily stumbled on a wordpress plugin that did the trick by somehow creating a .htaccess.swp file that contaied all my redirects which I imported from my txt document using the plugin.

    The plugin is called Redirection. I gave them a little donation as it saved me hours of grief with Bluehost who were unable to advise in any way. Not sure if this is the ideal solution or if I'll be able to figure out the correct way of doing this so if anyone has any ideas on the proper method I'd still love to know.

    I guess I can scrap the redirects after about 8 weeks to give the search cache time to update to the new redirected urls? Does anyone have advice on that?

    Cheers
     
Loading...

Share This Page