PHP parsing error

Status
Not open for further replies.

rubingv

New Member
Messages
1
Reaction score
0
Points
0
I want to add php content to my already existing html files. So I decided to parse php inside html file through a modification of .htaccess file by adding the following code>
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
But all I could find was to download the file when running the php-added-html files and the server is not parsing php.
So I request you to solve the problem as early as possible
Regards
Rubin
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
why not change the extension to .php?

Shouldn't be that hard to rename all your files, (depending on how many you have)
 

ah-blabla

New Member
Messages
375
Reaction score
7
Points
0
I want to add php content to my already existing html files. So I decided to parse php inside html file through a modification of .htaccess file by adding the following code>
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
But all I could find was to download the file when running the php-added-html files and the server is not parsing php.
So I request you to solve the problem as early as possible
Regards
Rubin
That should work, but doesn't. Another method uses AddHandler instead of addtype, but that also doesn't work, i.e. I get an unprocessed php file both ways. It might be something to do with the server config, but it should work...

Update: I found this outlining the same problem -- it seems since SSI is enabled, this won't work. However what you can do is use SSI to include a php file with the code you want to run:
In the html file put:
Code:
<!--#include file="test.php" -->
This runs test.php as a normal php file.

In .htaccess put
Code:
AddHandler server-parsed .html
why not change the extension to .php?

Shouldn't be that hard to rename all your files, (depending on how many you have)
That isn't the point. He wants files with a different ending parsed as php, which is perfectly possible with apache. Renaming isn't that easy since you also have to make sure all links are correct etc...
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
The following should work:
Code:
AddHandler application/x-httpd-php5 .html
Personally, I find the above wasteful, as non-PHP files will still be parsed by PHP. Additionally, Apache can be configured so that file extensions can be left off of URLs, making it easy to change the type of files:
Code:
Options +MultiViews
or (2nd choice):
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On

    # Don't try to add extension if there already is one
    RewriteRule \.(php|s?html|png|jpg|gif|css|js|swf)([/?#].*)?$ - [L]

    RewriteCond %(DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^/?(.*[^/])/?$    $1.php [L]

    RewriteCond %{DOCUMENT_ROOT}/$1.shtml -f
    RewriteRule ^/?(.*[^/])/?$    $1.shtml [L]

    RewriteCond %{DOCUMENT_ROOT}/$1.html -f
    RewriteRule ^/?(.*[^/])/?$    $1.html [L]

    RewriteCond %{DOCUMENT_ROOT}/$1.png -f
    RewriteRule ^/?(.*[^/])$    $1.png [L]

    RewriteCond %{DOCUMENT_ROOT}/$1.gif -f
    RewriteRule ^/?(.*[^/])$    $1.gif [L]

    RewriteCond %{DOCUMENT_ROOT}/$1.jpg -f
    RewriteRule ^/?(.*[^/])$    $1.jpg [L]
</IfModule>
<IfModule !mod_rewrite.c>
    Options +MultiViews
</IfModule>

Leaving file extensions out of URLs is The Right Thing To Do, unless you're using the file extensions to tell a script what type it should send:
Code:
RewriteRule /foo/bar\.([^./]+)$ /foo/bar.php?type=$1 [QSA]
 
Status
Not open for further replies.
Top