Need help to replace HTML redirect with 301 redirect

Discussion in 'Site & Server Administration' started by Rasputin, Sep 25, 2006.

  1. #1
    Hi

    I'm just converting an old HTML site to a wordpress based site, hence all the page names have changed.

    When I searched for advice, it seemed that an HTML redirect in the head of each page would work - so I did that with seconds set to 0. But the old HTML pages still flash up for a couple of seconds, which looks a bit poor.

    So I guess I really need a 301 redirect in the .htaccess file. Can someone point me in the right direction for the right code so that every time any .HTML file is searched for in the site, it redirects to the main site index.php page. The old index.html (now replaced by index.php) is especially a problem, because browsers seem to look for the html version first, so anyone at all visiting the site gets a 2 second glimpse of the old site.

    Thanks for any help
     
    Rasputin, Sep 25, 2006 IP
  2. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    I doubt that your visitors explicitely ask for http://www.example.com/index.html. They probably ask for http://www.example.com/ and your server shows the index.html page first,... because it still exists.

    If you remove the index.html file, this problem will disappear. Your server should directly go to index.php.

    Regarding the other pages, if you think it is important to redirect the visitors, there are many web pages that explain how to do a 301 redirect, but it can get more tricky in the WordPress environment.

    Jean-Luc
     
    Jean-Luc, Sep 25, 2006 IP
  3. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #3
    A html (meta) redirect is most definately NOT OK. Use a 301 instead.
     
    mad4, Sep 25, 2006 IP
  4. Rasputin

    Rasputin Peon

    Messages:
    1,511
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks, 301 it is then...

    Jean-Luc, I had looked at your site earlier thanks. My htaccess skills are non-existent so if I don't know the exact code for my circmstances I am nervous about trying it...

    If I take as my starting point your suggestion:

    RedirectPermanent /old-file-name.html http://www.new-domain.com/new-directory/new-file-name.html

    I have about 70 pages - do I have to do this separately for every page or is there a 'wildcard' so I can say something like

    RedirectPermanent /*.html
    http://www.new-domain.com/index.php

    All old files were html, now there are no html files, and I am happy if they all redirect to the new home page rather than to specific pages in the new site.

    Cheers
     
    Rasputin, Sep 25, 2006 IP
  5. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I would try this .htaccess :
    Options +FollowSymlinks
    RewriteEngine on 
    RewriteRule ^.*\.html$ /  [R=301]
    Code (markup):
    If the .htaccess file already exists, add the lines in the file (not tested).

    Jean-Luc
     
    Jean-Luc, Sep 25, 2006 IP
  6. Rasputin

    Rasputin Peon

    Messages:
    1,511
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That doesn't seem to work - it tries to find the file file.html in the new version and tells me 'Sorry, no posts matched your criteria.'

    I only added the line
    RewriteRule ^.*\.html$ / [R=301]

    because the other two lines are already in the file (for the http:// to www redirect) - should I add them again? Overall at the moment I have

    RewriteEngine on
    Options +FollowSymLinks

    RewriteCond %{HTTP_HOST} ^sitename\.com$ [NC]
    RewriteRule ^(.*)$ http://www.sitename.com/$1 [R=301,L]
    RewriteRule ^.*\.html$ / [R=301]

    plus a few lines wordpress has added
     
    Rasputin, Sep 25, 2006 IP
  7. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This should work better :
    RewriteEngine on
    Options +FollowSymLinks
    
    RewriteCond %{HTTP_HOST} ^sitename\.com$ [NC]
    RewriteRule ^(.*)$ http://www.sitename.com/$1 [R=301,L]
    RewriteRule ^.*\.html$ http://www.sitename.com/ [R=301,L]
    
    ... WordPress stuff ...
    
    Code (markup):
    Jean-Luc
     
    Jean-Luc, Sep 25, 2006 IP
  8. Rasputin

    Rasputin Peon

    Messages:
    1,511
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Seems to work perfectly

    Do I still need to clear all the contents out of the old HTML files to avoid any risk of a duplicate content penalty or is that a waste of time now?

    Thanks again for your help
     
    Rasputin, Sep 25, 2006 IP