Log in

View Full Version : .html parsed as .php



jscheuer1
04-14-2007, 01:08 PM
If you can't or don't want to rename your existing files, you could force your webserver to parse even .html-files for PHP code. If you use Apache, you could add the "AddType application/x-httpd-php .php .html" to your .htaccess. But this is another story.

I found this in another thread and may want to use it for something not directly related to that thread. What I want to know is the best way to actually do this and, if this would result in any significant load on the server for .html pages that contain no PHP code. Also, could there be any other drawbacks to doing this?

Twey
04-14-2007, 01:52 PM
What I want to know is the best way to actually do thisThe best (well, only) way to do it is as mentioned, with an .htaccess or in the main httpd.conf file.
and, if this would result in any significant load on the server for .html pages that contain no PHP code.Depends. The main cost would be that of sending it through a PHP interpreter, which is less of a problem with mod_php, but more of a problem if you're using CGI, which will start up a new PHP interpreter process with each page processed.
Also, could there be any other drawbacks to doing this?Well, the standard PHP opening tags (<?, <?php, <script language="php">) would be out of bounds. Can't see that being much of a problem with HTML pages, but the former interferes with the XML prologue on XML or XHTML pages.

You're better off using mod_rewrite to redirect certain .html URLs to corresponding PHP pages, really.

jscheuer1
04-14-2007, 02:43 PM
I find myself with this answer, in the situation I imagine many of the folks we help who are newbies do. After all, I am practically a newbie with .htaccess and PHP. That is - I barely understand the answer. So, more questions:



and, if this would result in any significant load on the server for .html pages that contain no PHP code.

Depends. The main cost would be that of sending it through a PHP interpreter, which is less of a problem with mod_php, but more of a problem if you're using CGI, which will start up a new PHP interpreter process with each page processed.

How can I tell which is being used by the server? I'm just the webmaster, not the server admin.


You're better off using mod_rewrite to redirect certain .html URLs to corresponding PHP pages, really.

Where does that go? Can you give me an example for - say:

somedomain.com/index.html

being redirected to:

anotherdomain.com/somedir/somedir/index.html

Also, is there a way (example please, if yes) of redirecting all requests to one domain to a directory on another domain, even if the pages only exist on the other domain that is being redirected to?

Twey
04-14-2007, 02:54 PM
How can I tell which is being used by the server? I'm just the webmaster, not the server admin.Generally if you log in to your server you can see (if not modify) the config for your virtual host in /etc/httpd.conf (or /etc/apache2/httpd.conf, or similar).
Where does that go? Can you give me an example for - say:

somedomain.com/index.html

being redirected to:

anotherdomain.com/somedir/somedir/index.htmlI think the .htaccess file in / would look something like:
RewriteEngine On
RewriteRule ^/index.html$ http://anotherdomain.com/somedir/somedir/index.html
Also, is there a way (example please, if yes) of redirecting all requests to one domain to a directory on another domain, even if the pages only exist on the other domain that is being redirected to?Certainly:
RewriteRule ^/(.*) http://anotherdomain.com/somedir/somedir/$1They're just standard regular expressions, although the syntax differs slightly (which always confuses me) due to there being so many reserved characters for regex commonly found in URLs.

pcbrainbuster
04-14-2007, 03:01 PM
And besides htaccess is to powerful to just leave aside soooo -
http://www.javascriptkit.com/howto/htaccess.shtml

Its got alot of detaisl and even gives all the error codes too, all the navigtion for htaccess is at the bottom...