Using .html pages to run .php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
nikkib20
Forum Newbie
Posts: 7
Joined: Fri Dec 16, 2005 2:28 pm
Location: Cedar Rapids, IA

Using .html pages to run .php

Post by nikkib20 »

Hi guys,

I realize I must just be missing some simple thing to get this to work because from everything I've read it's not hard.
Ok I have http://gods-heros-myth.com/godpages/bellerophon.php all built with different php menus and such and it works great! However, I can not have all of my pages rename to .php and still expect to keep my search engine rankings.

So I've been told I still keep my extensions as .html and edit a .htaccess file to have the .html pages run the .php code. Well no matter what I do...this page does not run the php code http://gods-heros-myth.com/godpages/bellerophon.html You'll see at the bottom the footer isn't running.

I dragged the .htaccess file off of my server and edited to be this:
AddType application/x-httpd-php .php .htm .html

I saved it and uploaded it into the root, the directory of my menus, and the directory of my .html page. No luck...

There is a .nsconfig file in the root of my main directory as well, but I do not know what that does.

What am I doing wrong??

Thanks!!
User avatar
nikkib20
Forum Newbie
Posts: 7
Joined: Fri Dec 16, 2005 2:28 pm
Location: Cedar Rapids, IA

Post by nikkib20 »

Does no one know how to do this other than the couple of web pages out there that mention this? What are any of the things that could cause this to go wrong? I was thinking this would be an easy question for many of you in here....
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Perhaps you host does not allow you to change this via htaccess...i would contact them and ask them
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

just as easy:

use mod rewrite to rewrite all urls from html to php, now .html and .php will work on all your files
Simon.T
Forum Newbie
Posts: 6
Joined: Tue Dec 20, 2005 5:36 am
Location: Malaga, Spain

Post by Simon.T »

<script language="php"> include("../menus/footer.php");</script>
this is the last line of the code i saw when i looked at the link you posted,

i`ve never had this style of coding work and not sure if that would work on anything other than an ms server? (i have no idea really!!!)

depending on your server config this wont work, instead try using

Code: Select all

<? include("../menus/footer.php"); ?>
or

Code: Select all

<?php include("../menus/footer.php"); ?>
if anyone else is looking at this can you tell me the rules when you can use this style
<script language="php"> include("../menus/footer.php");</script>
Simon
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Simon.T wrote:
<script language="php"> include("../menus/footer.php");</script>
this is the last line of the code i saw when i looked at the link you posted,

i`ve never had this style of coding work and not sure if that would work on anything other than an ms server? (i have no idea really!!!)

Simon
Not seen that before myself, but i have just tried in on my server (apache) and it worked no problem :?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

This may help

http://fundisom.com/phparadise/php/html ... HP_in_HTML
AddType application/x-httpd-php .html .htm
User avatar
nikkib20
Forum Newbie
Posts: 7
Joined: Fri Dec 16, 2005 2:28 pm
Location: Cedar Rapids, IA

Post by nikkib20 »

I'm able to drag .htaccess off of my server, change it and then upload it...no problems so I will try the above.

WIth regards to the coding, it's not standard php, honestly I used it as a cut and paste from another website I'm cleaning up as a quick test. It works just fine on .php strings, but the problem above is a pain.

I can not afford to rename my pages to .php and lose my rankings. I'll let you guys know, thanks a lot :)
User avatar
nikkib20
Forum Newbie
Posts: 7
Joined: Fri Dec 16, 2005 2:28 pm
Location: Cedar Rapids, IA

Post by nikkib20 »

Ok guys, how would this method work?

just as easy:

use mod rewrite to rewrite all urls from html to php, now .html and .php will work on all your files
User avatar
nikkib20
Forum Newbie
Posts: 7
Joined: Fri Dec 16, 2005 2:28 pm
Location: Cedar Rapids, IA

Post by nikkib20 »

Ok I'm sol on .htaccess

NOTE: Due to our enhanced security policies, you will be unable to change the default handler for .html, .php, or .cgi files.


Anyone know how to do the mod method above?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

nikkib20 wrote:Anyone know how to do the mod method above?
It's just basic POSIX regex. mod_rewrite support must be compiled into apache before you do anything else. phpinfo() would show if that's the case or not ;)

In a .htaccess you'd simply do (untested)

Code: Select all

RewriteEngine On
RewriteBase  /

RewriteRule   ^([a-zA-Z0-9_]+)\.html(.*)$     $1.php$2
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

I thought he said he didn't have htaccess access, either that or I misunderstood and he just cannot change the default handlers (I think this might be what he meant)

Code: Select all

RewriteEngine On
RewriteRule *\.html $1.php
put that in an htaccess file, and if you don't get a 500 error then you should be good to go, to test it make a hello_world.php and type yourdomain.com/hello_world.html. All it's doing is making the URL look like a html

d11 - you can't access the query string like that

Code: Select all

# Search script
RewriteCond	%{QUERY_STRING}		q=(.*)
RewriteRule	^search$		search.php?q=%1 [L]
I use something like that usually, it rewirtes "search?q=test" to "search.php?q=test"
User avatar
nikkib20
Forum Newbie
Posts: 7
Joined: Fri Dec 16, 2005 2:28 pm
Location: Cedar Rapids, IA

Post by nikkib20 »

ok I'm switching hosts, will let you know how it goes. THanks for the help!
vincenzobar
Forum Commoner
Posts: 95
Joined: Wed Nov 02, 2005 9:57 am

Post by vincenzobar »

last i heard google doesn't like IP changes!
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

All depending on your Apache compilation. If your .conf does alow you to overwrite with .htaccess you can do it with .htaccess. If not you need to change your .conf and restart apache.
Post Reply