Philippe27 Posted May 9, 2009 Share Posted May 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/ Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830341 Share on other sites More sharing options...
Philippe27 Posted May 9, 2009 Author Share Posted May 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830349 Share on other sites More sharing options...
PFMaBiSmAd Posted May 9, 2009 Share Posted May 9, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830353 Share on other sites More sharing options...
Philippe27 Posted May 9, 2009 Author Share Posted May 9, 2009 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" Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830355 Share on other sites More sharing options...
wildteen88 Posted May 9, 2009 Share Posted May 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830359 Share on other sites More sharing options...
Philippe27 Posted May 9, 2009 Author Share Posted May 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830362 Share on other sites More sharing options...
wildteen88 Posted May 9, 2009 Share Posted May 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830364 Share on other sites More sharing options...
Philippe27 Posted May 9, 2009 Author Share Posted May 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830366 Share on other sites More sharing options...
PFMaBiSmAd Posted May 9, 2009 Share Posted May 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830370 Share on other sites More sharing options...
Philippe27 Posted May 9, 2009 Author Share Posted May 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157494-newbie-question-parse-php-to-htm/#findComment-830377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.