Moving from htm to php

design

#1

We are revising our site, moving from htm files to php.

What is the most graceful way to implement this for our users? I want to minimize broken Favorites or search file destinations if I can.

I thought there was a way to tell the Dreamhost server: If someone asks for a file.htm that doesn’t exist, try file.php before giving up.

Is there a service that will do that here? or can someone suggest a script?

Many thanks,
Joyce


#2

Assuming you intend to move all of your htm files to php, the easiest way to accomplish this is using .htaccess. If you create a .htaccess file in the root of your site and add the following line, everything should work just fine:


#3

Thanks. Is this “all or nothing”? or does it kick in only when there’s an error?

In other words, for the most part I have
filename.htm AND filename.php and intend to delete the .htm’s

However, the php’s sometimes call .html files. Will those be okay? or will the system try to find a php by that name?

And if there is an htm file for which there is no php, will it display the htm file or an error?

Thank you,
Joyce


#4

If you mean by using the PHP include or require commands, yes, those will work just fine, meaning that it will load the .html file no matter what you put in .htaccess. The reason they won’t be affected is because what that command I showed before does is create a rewrite rule for mod_rewrite that affects only browser requests. When you use include or require from your PHP script, that all happens inside PHP, so it’s not a browser request, and therefore is unaffected.

It will generate a 404 Not Found error. The reason is that mod_rewrite rules normally operate without knowing anything about the files that actually exist, living in a world of pure string manipulation based on what the browser requested. However, if you want it to fall back on the old htm file if there is no PHP file yet, check out the technique described here in the section titled “Backward Compatibility for YYYY to XXXX migration”

mod_rewrite is a pretty powerful tool and you can do a lot of really nifty things with it. You might want to take a look at the documentation to get a better idea of how it works and what you can accomplish.


#5

Thank you.

We have a couple of “sub-webs” – these will also be affected by the rewrite command, right? So I have to convert those as well before I dare implement the rewrite?

Best wishes,
Joyce


#6

The short answer is yes, they will be affected by the rewrite command.

The long answer is that a “sub-web” is really just a directory on the server underneath your document root. Rewrite rules in .htaccess apply beginning with the directory that contains the .htaccess file and all of the subdirectories below. Thus, if you place your .htaccess file in your document root, it will apply everywhere. If you only want to affect some subdirectories but not others, only place copies of the .htaccess file in those subdirectories which you want to convert.