Forum Moderators: phranque
Thanks in advance.
AddHandler server-parsed .shtml .html
See [httpd.apache.org ] for a one way to accomplish this. You could also use mod_rewrite, but this is basic enough that it's not really necessary unless you want the URL in the browser to still be the .html version. If you needed to expand it, so that *all* .html files were rewritten to their .php counterparts, you could use RedirectMatch (or, again, mod_rewrite). I *do* like mod_rewrite, but I prefer not to use it if it's not really necessary; bit like swatting a fly with submarine. =)
But then I kept getting the following error:
Redirection limit for URL exceeded, unable to load the requested page, this maybe caused by blocked cookies.
So in despair, I then deleted the redirect command, and now it works fine on MY computer.
I'm really confused. Can someone explain what is happening?
Options +FollowSymlinks
RewriteEngine on
# redirects from index.html to index.php
RewriteRule ^directory/index.html$ [mysite.com...] [R=301,L]
I don't think the AddHandler method is so bad. After all, php only has to look at the file and pass it on, that hardly counts as parsing. And what if every page had php code on it anyway?
BIG problemat all.
you've now told Apache that *all* HTML files need to be handed to PHP so that the PHP engine can parse the file looking for <?php?> tags. The overhead involved lowers server capacity and is, generally speaking....well, a bit dumb. Sorry. =)
Apology accepted ;)
Please understand that using the AddHandler as described by encyclo allows you to accomplish exactly what you wanted -- parse your server-side technology files. If you are using PHP on all your pages it only makes sense to parse those files accordingly. If you don't you are going to send raw PHP commands to the browser -- ouch.
When you are running a dynamic site, you have to allow server-side processing. The AddHandler method works, and works well on Apache 2.0 and the overhead calls are minimal, at best.
You can therefore target just one file to be parsed for PHP. Place the following in a .htaccess within the folder which contains the index.html you want parsed:
<Files index.html>
ForceType application/x-httpd-php
</Files> Still no need for redirects (which are best avoided unless there is really no other way), no significant extra server load, and caching is preserved for the other static HTML files on the site. Will that do? ;)