.htaccess 301 redirect while converting HTML site to WordPress

Discussion in 'Apache' started by Ajeet, Jun 30, 2010.

  1. #1
    Hi,

    I am converting my static HTML site to WordPress. So I will need to make sure that I 301 all my old pages.

    My HTML pages were all of the format: http://www.domain.com/page1.html
    I plan on converting each such page to a WordPress post which will have a URL like:
    http://www.domain.com/categoryname/page1/

    I have two questions I hope you can help me with:

    1) Since I am not changing the domain name, would my 301 redirect in the .htaccess be:
    redirect 301 /page1.html http://www.domain.com/categoryname/page1/
    OR
    redirect 301 /page1.html /categoryname/page1/ (i.e. not the full URL)

    2) My understanding is that I will need to put an entry each for all the pages. Is that right?
    redirect 301 /page1.html http://www.domain.com/categoryname/page1/
    redirect 301 /page2.html http://www.domain.com/categoryname/page2/
    redirect 301 /page3.html http://www.domain.com/categoryname/page3/
    redirect 301 /page4.html http://www.domain.com/categoryname/page4/
    redirect 301 /page5.html http://www.domain.com/categoryname/page5/
    …

    Thanks for your help.
    Ajeet
     
    Ajeet, Jun 30, 2010 IP
  2. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #2
    Hi instead use a ReWriteCond, and ReWriteRule to redirect your old urls.

    RewriteRule (.*)\.html$ http://www.domain.com/categoryname/$1 [R=301,L]

    Try it.
    I hope it will work...
     
    Imran, Jul 5, 2010 IP
  3. Ajeet

    Ajeet Well-Known Member

    Messages:
    2,511
    Likes Received:
    503
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Thanks for that Imran. What I am worried about is the fact that the new URLs have a trailing "/" while the old URLs did not. Will that be taken care of with the above redirect?
     
    Ajeet, Jul 5, 2010 IP
  4. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #4
    Trailing slash should not be a problem.
     
    Imran, Jul 7, 2010 IP
    Ajeet likes this.
  5. Ajeet

    Ajeet Well-Known Member

    Messages:
    2,511
    Likes Received:
    503
    Best Answers:
    0
    Trophy Points:
    185
    #5
    Fabulous. Thanks. The only thing is that to make this syntax work, I had to use the same categoryname in the URL http://www.domain.com/categoryname/ Any way around that.

    Thanks
    (green rep coming your way :)
     
    Ajeet, Jul 7, 2010 IP
  6. arpitagarwal82

    arpitagarwal82 Notable Member

    Messages:
    2,996
    Likes Received:
    398
    Best Answers:
    0
    Trophy Points:
    280
    #6
    arpitagarwal82, Jul 7, 2010 IP
  7. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #7
    To make use of Wordpress SEF urls it is better to have a different structure.

    The above syntax will change for Categories with different names.
    Give me a category structure that you have and want to have in new wordpress.
    I will give it a try again.
     
    Imran, Jul 10, 2010 IP
  8. Ajeet

    Ajeet Well-Known Member

    Messages:
    2,511
    Likes Received:
    503
    Best Answers:
    0
    Trophy Points:
    185
    #8
    Okay, suppose these are the redirections from my html site to WP site, then how would the redirections work?

    http://www.domain.com/page1.html redirects to http://www.domain.com/categoryONE/page1/
    http://www.domain.com/page2.html redirects to http://www.domain.com/categoryTWO/page2/
    http://www.domain.com/page3.html redirects to http://www.domain.com/categoryTWO/page3/
    http://www.domain.com/page4.html redirects to http://www.domain.com/categoryTWO/page4/
    http://www.domain.com/page5.html redirects to http://www.domain.com/categoryTWO/page5/
    http://www.domain.com/page6.html redirects to http://www.domain.com/categoryTHREE/page6/
    http://www.domain.com/page7.html redirects to http://www.domain.com/categoryTHREE/page7/

    Thanks :)
     
    Ajeet, Jul 10, 2010 IP
  9. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #9
    Imran, Jul 10, 2010 IP
  10. Ajeet

    Ajeet Well-Known Member

    Messages:
    2,511
    Likes Received:
    503
    Best Answers:
    0
    Trophy Points:
    185
    #10
    Thanks Imran. You have been very helpful :)
     
    Ajeet, Jul 10, 2010 IP
  11. Imran

    Imran Notable Member

    Messages:
    2,340
    Likes Received:
    190
    Best Answers:
    0
    Trophy Points:
    230
    #11
    I'm glad, I was able to help.
     
    Imran, Jul 10, 2010 IP
  12. arpitagarwal82

    arpitagarwal82 Notable Member

    Messages:
    2,996
    Likes Received:
    398
    Best Answers:
    0
    Trophy Points:
    280
    #12
    We can simply use /%postname%.html in permalink to get that structure for posts URL
     
    arpitagarwal82, Jul 10, 2010 IP