Helpful Information
Category: Apache configuration
htaccess - directing and allowing

I had a site change from "html" extensions over to "shtml". Some files are "htm" and those were good to stay that way. Someone advised to put this as my htaccess file to convert any "html" over to "shtml" ...

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.htm$ $1 [C,E=WasHTML:yes]
RewriteCond %{REQUEST_FILENAME}.shtml -f
RewriteRule ^(.*)$ $1.shtml [S=1,R]
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ $1.htm

No problem. Works perfectly.

Now my site is going over to a "php" extension. One problem though, a few pages are going to stay as "shtml" on them. There are still the few from previous that are still staying "htm" too.

So the question is... how do I adjust my htaccess file now? Most pages used to be shtml but are now php. There are a few pages that must be left as shtml so I dont want "all" traffic directed to "php" only. Any htaccess gurus around for this? Or any workarounds if it means putting these few into a different directory or whatever...


For anyones reference, I got it to work by adding this...

AddType text/html .php
AddHandler server-parsed .php
Options Indexes FollowSymLinks Includes

That makes php files able to parse ssi stuff.

So all that may be a "messy" way of doing things perhaps? I dunno htaccess enough to know if it is or not. If you have any "cleaner" solutions, thanks.

Um... so that let me parse SSI commands using a PHP extension, so I was able to translate most of my SHTML pages over to PHP, but... I still have a few that cannot be changed over to PHP, so my original problem still exists...
How do I adjust the first posting code so that anyone accessing "whatever.shtml" will be sent over to "whatever.php" automatically PLUS be able to keep a few "whatever.shtml" pages available as is?

And just a side question relating to the extra code I had added shown in this posting... Does it really slow things down alot if only a few PHP pages will be using the SSI abilities? Oh well, I guess that will be a mute point if I get that first problem solved anyways wont it?

Sorry if that all sounds confusing. Its late here and my brian is a bit fuzzy :D

Ok, for those who come across this in the future (possibly me again) here is the solution...

Backward Compatibility for YYYY to XXXX migration
How can we make URLs backward compatible (still existing virtually) after migrating document.YYYY to document.XXXX, e.g. after translating a bunch of .html files to .phtml?
We just rewrite the name to its basename and test for existence of the new extension. If it exists, we take that name, else we rewrite the URL to its original state. # backward compatibility ruleset for
# rewriting document.html to document.phtml
# when and only when document.phtml exists
# but no longer document.html
RewriteEngine on
RewriteBase /~quux/
# parse out basename, but remember the fact
RewriteRule ^(.*)\.html$ $1 [C,E=WasHTML:yes]
# rewrite to document.phtml if exists
RewriteCond %{REQUEST_FILENAME}.phtml -f
RewriteRule ^(.*)$ $1.phtml [S=1]
# else reverse the previous basename cutout
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ $1.html

As found on this page...

privacy (GDPR)