skip to Main Content

I have a 2 year old static HTML and CSS website. The site has over 150 pages and it’s too much work to keep it updated (like sidebar content, menu, head section or footer).

So now I want to convert my static HTML and CSS website to PHP (and use php includes), but because of SEO reasons (backlinks to my site) I want to keep the .html file extension.

Example:

www.example.com/malware.php becomes www.example.com/malware.html

Before I used Server Side Includes, but found out that SSI’s cause security problems like SSI injections (happened to me).

My website is hosted on A2 Hosting (TURBO shared hosting account) https://www.a2hosting.com/web-hosting/compare.

Which lines of code in the .htaccess file can do this?

3

Answers


  1. Chosen as BEST ANSWER

    Thanks everybody for your answers, but i just found the solution after searching for awhile. I've just included the following lines in the .htaccess file and it works.

    RewriteEngine on
    RewriteRule ^(.*).html$ $1.php [nc]
    

  2. Add this in your .htaccess file

    RewriteEngine on
    
    RewriteRule ^(.*).php /$1.html [R=301,L]
    
    Login or Signup to reply.
  3. There are two different ways to have Apache interpret .html as .php and handle them as such.

    Normally, you’d use this:

    AddHandler application/x-httpd-php5 .php .html .htm
    

    But I’ve found for some shared hosting accounts, you need to adjust this command, and use the following.

    AddHandler cgi-script .html 
    SetEnv PHP_EXTENSION .html
    

    Do bear in mind that this will increase the server load for your website, but unless you do something very stupid (which your host will protect against) you should be fine.

    You can perform a 301 redirect as outlined in these other answers, and Google will certainly re-index your website fairly quickly. However there will be a couple of weeks of your website’s position in the search result fluctuating.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search