0

I maintain a website that contains a dozen or so .html documents which I have just rewritten to include php code. As search engines currently index the .html documents, I would rather not break those links and I certainly don't want to do anything that will affect my search rankings. I understand I have a couple of choices.

Option 1 is to replace all the .html extensions on my documents with .php, and then update .htaccess so that requests for .html documents are rewritten/redirected to the corresponding .php documents (as suggested here).

If I want to make this a permanent (301) redirection, so that the search engine links are replaced the next time my site is crawled, is this the correct way to do this?

RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L,R301]

Option 2 would be to instruct the webserver to send all html documents through the php parser (as suggested here), which means the .html extension on the the files doesn't need to be changed at all:

AddType application/x-httpd-php .htm .html

So I see two viable choices. Is one better than the other (or can you think of a better one)?

Community
  • 1
  • 1
JCOidl
  • 452
  • 1
  • 5
  • 12

1 Answers1

1

The first method means you need to rename all of your html files to php files and for a little while, a marginal amount of extra traffic for the redirects.

The second method means you don't need to change anything at all and html files get processed by the PHP handler like php files do.

First method is more work but it also means your site is more portable. Meaning that if you copy your site to a new host that, say, doesn't give you the ability to change the handler types, then you will still be fine because your files end with the php extension.

The second method is less work and won't require search engines to re-index your site but will make your site a little less portable.

Note that you can also use mod_alias to redirect:

RedirectMatch 301 ^/(.*).html$ /$1.php 
Jon Lin
  • 142,182
  • 29
  • 220
  • 220