Tech talk, social media, blogging, computing tips and tricks

Static Pages in WordPress

October 24th, 2008 by David Bradley >> 6 Comments

php-logoSciencetext reader Keith N emailed with a question about the post I wrote explaining how to make html pages work like WordPress. In that post I explained how to make pages ‘outside’ the WordPress blog work as if they were within the blog system. This is what Keith had to say:

“I have many static pages that I want to create new ones for to work with WordPress but I don’t know how to get that done. I see you’ve found a hack for HTML, but what if I take the code I have for the files and then save the file as a PHP file but use the same lines of code you did for the HTML conversions….would that work?”

Okay, there’s a bit of confusion in Keith’s question regarding “making” PHP files. When you add the PHP code I suggested to those non-Wordpress pages you have to tell your server to parse (or run) those files (which have the .html or .htm extension) as PHP. By tweaking your .htaccess file (as I said in the original post), you make them behave as PHP files. It is the code within a file that makes it a PHP file not the file extension. They actually ARE php files, they just have the “wrong” extension.

However, I also wonder as to why Keith needs to make these outside pages work within the WordPress system. Obviously, there are the advantages of being able to apply to them the WordPress theme he’s chosen. But, why not simply recreate the pages as actual WordPress Pages (capital P)? That way you could enable comments too, something that isn’t possible with my legacy pages.

There is one good reason, which is why I had to get my old .html pages to work as WordPress PHP pages, and that is if they have lots of internal links among them AND lots of links from other websites. If you simply change the .html extension to .php those links and their page rank in the search engines would be lost.

This is the code to add to the .htaccess file in the root of your website to make your server parse files with either the .html or .htm extension behave as PHP files:

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

If Keith’s or your pages don’t have any rank or inbound links then don’t worry about converting their extension to .php. BUT, if you’re going to make that change, then you might as well simply create formal WordPress Pages (capital P) within the WordPress hierarchy from scratch.

There is an alternative though. You could rebuild the pages as Pages, within WordPress and then write an appropriate rewrites or 301 redirect for each page in your root .htaccess file, that will preserve the connections from internal and external links as well as page rank (after a month or so).

The bottom line is: if you have only a few non-ranking pages create proper WordPress Pages for any content and delete the originals and redirect. If you have lots of pages, then use my technique.


Leave a comment ↓

  • Keith N // Oct 24, 2008 at 5:22 pm

    David,

    Thanks for the reply and the post. I guess I should have been more clear with my question, but I was seeking a quick fix I guess for my situation. If you visit my site – http://www.ustfccca.org – you will see pages upon pages that include both text and links. The posts and features I am not concerned with. However, I am concerned with my awards section which includes all of the awards we’ve given out over the past few years. These pages are more like lists – http://ustfccca.cstv.com/ot/ustca-awards.html – with links to pages for that particular award. What my thought is for these pages and others like this is to take my theme’s header, sidebar and footer and have it dynamically appear on those pages so I don’t have to recreate the content or build out new pages.

    If there is an easier way, please let me know. Once again thanks for the prompt reply.

  • David Bradley // Oct 24, 2008 at 5:27 pm

    Okay. I get you. You need a search and replace tool that will allow you to add the WordPress includes. There’s no way to just “make” these hundreds of pages behave like WordPress themed pages without doing the legwork, I’m afraid. Backup before you start!

  • Kim Woodbridge // Oct 24, 2008 at 9:10 pm

    Thanks for the additional information about this. I’m still thinking about the site I want to convert to WordPress and I do think using redirects is the best way for me to handle it.

  • shaz // Apr 9, 2009 at 4:15 pm

    hi David,

    I think you may be able to help me here. FYI – I’m currently running on WP 2.7 platform.

    As you can see, my root folder (www.shazas.com) is the main blog site and I’m actually trying to create a subfolder using a static HTML page. I have files from previous sites and I’d like to make it appear as http://www.shazas.com/subfolder.

    Do you think you could be kind enough to help me please? Thanks

  • David Bradley // Apr 9, 2009 at 5:17 pm

    Just follow the instructions I published here and you should be fine. You may have to tweak the code that goes at the top so that it works with a subfolder rather than from a wordpress install rendering files in the root.

  • shaz // Apr 10, 2009 at 2:28 am

    i followed your instructions and it still didnt work. below is how my .htaccess file content looks like:

    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
    php_value zend_extension /usr/home/shazasco/ioncube_loader_lin_4.3.so
    AddHandler application/x-httpd-php .php .html .htm

    order deny,allow
    deny from all
    allow from all

    order deny,allow
    deny from all

    AuthName shazas.com

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress
    RewriteCond %{HTTP_HOST} ^shazas.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.shazas.com$
    RewriteRule ^advertise/?(.*)$ “http\:\/\/www\.shazas\.com\/$1″ [R=302,L]

    is there something wrong there? thanks for the help :)