Jump to content

Recommended Posts

First of all I'm a newbie and first time I'm trying to use .php. What I basically want to do is have all my pages as .htm but still be able to use .php codes in them. I know my .php code is working because when I rename my page to "test.php" it all works but it doesn't as "test.htm".

 

From what I understand I need to create a .htaccess file and put some text in it. I've looked around and can't seem to find anything that works. My server is netfirms and in my settings I have "htaccess: enabled" and "PHP version PHP 4".

 

When I go in the netfirms help all I see is this:

 

"Example #14:

The following example allows visitors to browse to .html pages and parse them as PHP pages (.html will be retained in the URL):

 

RewriteEngine On

Rewritebase /

RewriteRule ^index.htm$ index.php [L,NE]

RewriteRule ^(.*).htm $1.php [QSA,L]"

 

I receive the following message:

"Not Found

 

The requested URL /links.php was not found on this server."

so I don't think that's the right code and I didn't see that code anywhere else. At least this tells me my .htaccess file works, I just need to find the right code.

 

Can anyone help?

Thanks

Phil

Link to comment
https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/
Share on other sites

You just need to add this in your htaccess (nothing else)

 

AddType application/x-httpd-php .htm .php

 

Just as a foot note you really should be using PHP5 not PHP4

 

I tried that and doesn't seem to be working.

Now for some reason when i go to the URL it opens a window and asks me what program I want to use to open the page (using Firefox) and using IE it just shows up without the menu part I want included.

This is the link: http://www.ultimateffstrategy.com/links.htm

The example #14 .htaccess file you found does not do exactly what it states. It does not cause .htm/.html pages to be parsed as PHP pages. It rewrites .html (.htm in your case) URL's into .php URL's. Meaning it expects your actual files to be .php. This opens the possibility for a lot of confusion and it also prevents you from having actual .html/.htm files.

 

The line that gevans posted should do what you intend (and what the example $14 states), causing .htm pages to be parsed as php pages.

 

Edit: For your last post, post your actual code in the file and what does a "view source" in your browser show?

The example #14 .htaccess file you found does not do exactly what it states. It does not cause .htm/.html pages to be parsed as PHP pages. It rewrites .html (.htm in your case) URL's into .php URL's. Meaning it expects your actual files to be .php. This opens the possibility for a lot of confusion and it also prevents you from having actual .html/.htm files.

 

The line that gevans posted should do what you intend (and what the example $14 states), causing .htm pages to be parsed as php pages.

 

Edit: For your last post, post your actual code in the file and what does a "view source" in your browser show?

 

When I go t view source I get this:

.......

</script>

</head>

 

<?php include("menu.php"); ?>

 

<table border="0" cellpadding="0" width="990" cellspacing="0" style="padding: 0">

  <tr>

    <td width="160" bgcolor="#D2D2FF" valign="top" style="border-right: 2px solid #FFFFFF; " bordercolorlight="#F5F5F5" bordercolordark="#C8C8C8">

......

 

From what i read somewhere else it shouldn't show the "<?php include("menu.php"); ?>" part so there's something wrong I think.

 

In my htaccess file all Ihave is what gevans posted: "AddType application/x-httpd-php .htm .php"

In order for that line to work your actuall files will need to be named as filename.htm not as filename.php. As that line now parse's .htm files as .php files.

 

Yeah they are but does that include the part I want included?

Basically I have a page links.htm and a page named menu.php.

I want the menu.php part to appear in the links.htm page. Everything works if I call it links.php but I also want it to work if I call it links.htm.

No files that are included/required can have any file extension. Only the parent file needs to be have a .php extension (or in your case .htm)

 

Example

test.php

<?php
include 'non-php-file.txt';
?>

 

non-php-file.txt

<?php echo 'Hello, Word'; ?>

 

When you run test.php the message "Hello, World" will be displayed

No files that are included/required can have any file extension. Only the parent file needs to be have a .php extension (or in your case .htm)

 

Example

test.php

<?php
include 'non-php-file.txt';
?>

 

non-php-file.txt

<?php echo 'Hello, Word'; ?>

 

When you run test.php the message "Hello, World" will be displayed

 

Yeah in that case I have it right, the parent file (file I open and want php code included in) is called links.htm

I believe the AddType directive does not work when php is running as a CGI application. Try the following -

AddHandler application/x-httpd-php .htm .php

 

The page shows up fine now but still no menu.

I also realized that if I rename the page to links.php the menu won't show up BUT if I remove the .htaccess file the links.php page shows up properly with the menu.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.