Re: why php echo does not show up in HTML? [message #181663 is a reply to message #181660] |
Fri, 24 May 2013 19:34 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 5/24/2013 2:26 PM, J.O. Aho wrote:
> On 24/05/13 11:06, steve nospam wrote:
>
>> I found the problem.
>>
>> I needed to modify the .htaccess file. added this line
>>
>> AddType application/x-httpd-php .htm
>>
>> Now it works. php works from inside htm file. No need to change file
>> extension.
>
> No, you didn't solve anything at all, you just managed to break your
> site to not work properly.
>
> When you add that line, all the pages ending with ".htm" will be sent
> trough the PHP parser and the majority of your pages will not include
> PHP which means you do something unnecessary by sending them to the PHP
> engine which has to read the whole file and do nothing more.
>
> The fix is rename the files to .php and remove the line from your
> htaccess file. If pages which before been called whatever.htm will
> suddenly be whatever.php, then use Rewrite rules to redirect the user to
> the new page.
>
> RewriteEngine On
> RewriteRule ^whatever.htm$ whatever.php
>
> Now your site will work at the majority of web hosting companies as you
> have your PHP in .php files and RewriteRule is in most cases allowed.
>
>
> Note: When people say you can use PHP in HTML, they ain't talking about
> the file extension, but that you can mix plain HTML with PHP code, for
> example:
>
> --- example.php ---
> <html>
> <head>
> <title>example file with mixed php and html</title>
> </head>
> <body>
> <h1><?php echo "this is an example"; ?></h1>
> <?php echo "this code is quite stupid, but shows how you can make a
> badly coded site"; ?>
> </body>
> </html>
> --- eof ---
>
This also only bypasses the problem - and will require a redirect for
the life of the website (even if he changes hosts).
Better is to put in a 301 redirect for the pages; search engines will
pick up the redirect and link to the new page.
It can be done easily in the .htaccess file (more info on how to do it
correctly an alt.apache.configuration).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|