Forum Moderators: open

Message Too Old, No Replies

including another file with a link inside the body

         

flycast

11:15 pm on Jan 23, 2005 (gmt 0)

10+ Year Member



Is there a way to simulate the php include() statement in html that does not require php but only html? I have a bunch of html files that all have the exact same navagation coded into each file. I want to move the navagation code to one file and then include it into the html as the page is requested.

I have done this sucessfully in the past by inserting an include() statement inside php tags and running the html page through the php interpeter. Problem is that in this case I don't think that the host will let me run those html files through the php interpeter.

I have looked around in html at some of the tags that are not sure as much and as yet havn't found a way.

Any ideas?

supermanjnk

1:49 pm on Jan 24, 2005 (gmt 0)

10+ Year Member



Does your host allow serverside includes? if so you could try those.

Justin_L

7:58 pm on Jan 24, 2005 (gmt 0)

10+ Year Member



"Problem is that in this case I don't think that the host will let me run those html files through the php interpeter. "

If it were me, I'd get a new host and use php.

valder

8:16 pm on Jan 24, 2005 (gmt 0)

10+ Year Member



Excuse me if this is a silly suggestion, but if your server has php installed, why don't you use it? Rename the html files to php and include
"
<?php include('filename'); ?>
" where needed.

flycast

12:37 am on Jan 25, 2005 (gmt 0)

10+ Year Member



I don't want to rename the 70-some files. That means making sure that all the links (there's a ton) all have the correctly renamed files.

I am hesitant to suggest to the client that they need to change servers if I havn't determined weather I can work out a solution on their current server first.

larryhatch

1:01 am on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Valder:

Is it really that simple? I have a site with 150 pages, all of them .html

Could I simply rename them all to (whatever).php, and just fix the internal links to match?

How about index.html? Would that also work, and what are the risks with respect to incoming links?

- Larry

valder

2:02 am on Jan 25, 2005 (gmt 0)

10+ Year Member



Larry,

If your server has php installed, then yes, it should be that simple. PHP only parses what is between <?php and?>, so you could just rename your html-files to php and it would be the same.

You may need to set the default index page accordingly. On most shared servers with php installed, this may probably not be a concern.

In apache, you set the index page with DirectoryIndex.
For instance,

DirectoryIndex index.php
or
DirectoryIndex index.php index.html xyz.htm
.

For incoming links, you could use some mod_rewrite code to redirect requests for .html to .php. That's real simple;

Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*)\.html $1\.php [L]

Here's some reading material for you:
The apache manual [httpd.apache.org] ¦ Apache's mod_dir manual pages [httpd.apache.org] ¦ Apache's mod_rewrite-guide [httpd.apache.org] ¦ mod_rewrite manual [httpd.apache.org] ¦ PHP tutorial [w3schools.com]
(see my profile's homepage for more resources)

And be sure to visit the Apache forum [webmasterworld.com] here on WebmasterWorld, but please read up on some of it before asking stupid questions thank you. ;) (just kidding)

Eivind

valder

2:15 am on Jan 25, 2005 (gmt 0)

10+ Year Member



Flycast,

I don't think you'd have to rename everything manually.

Are you in windows world? Perhaps

ren *.html *.php
would do the trick? I won't take responsibility for any screw-up on that one, so be sure to test it first on something harmless. In fact, I have no idea, because it's been a while since I was using windows. Maybe it'll work, maybe not at all.

When it comes to renaming the text inside the files, it should be pretty simple. In fact, this has been discussed [webmasterworld.com] earlier today.

Eivind

mrnoisy

5:44 am on Jan 25, 2005 (gmt 0)

10+ Year Member



Here's something I found on WebmasterWorld and it changed my life.

Start with a blank text file and paste in the following line:


AddHandler application/x-httpd-php .html

Then save the file as .htaccess and upload it to the root (httpdocs) folder on your webserver.

This allows you to run php scripts in files with a .html extension.

larryhatch

6:45 am on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Valder and Mr. Noisy too.

Obviously I have a LOT to learn. Please forgive one more really dumb question though:

Briefly as possible, what are the main major advantages of changing from all html to php files?

larryhatch

7:30 am on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Valder & mrnoisy:

Please disregard my previous dumb question of the value of PHP.
I read up on the PHP tutorial (righthand link given by Valder) and its an eye opener!

Looks a lot like C-language, and it executes Server Side.
Code is thus invisible to browsers who "View Source"
This answers an unrelated question (sorry, off topic) of how certain PR hogs operate.
I could never understand it before.

Scraperhog links to my my site with a target UFL something like www.scraper.com/Sites.php?site#123
Sites.php interprets site#123 into my actual URL so visitors are referred my way.

I can't see code for sites.php because it is never downloaded to my machine.
Scraper probably has that php in a directory nobody else can see, not even the search engines.

Still off-topic, does anyone know of Google can see thru or get past this to pass PR? -Larry

larryhatch

7:34 am on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mrnoisy: Thank you VERY much for this:

Start with a blank text file and paste in the following line:

AddHandler application/x-httpd-php .html

Then save the file as .htaccess and upload it to the root (httpdocs) folder on your webserver.

This allows you to run php scripts in files with a .html extension.

- - -

That looks like what I need, assuming my host allows it.

One quibble: I already have an .htaccess file up to redirect mysite.net to www.mysite.net
If I send up a NEW htaccess, I will overwrite the old one.
Can somebody walk me thru, stitching the two operations together into a single .htaccess file?

Thanks - Larry

mrnoisy

7:59 am on Jan 25, 2005 (gmt 0)

10+ Year Member



One quibble: I already have an .htaccess file up to redirect mysite.net to www.mysite.net
If I send up a NEW htaccess, I will overwrite the old one.
Can somebody walk me thru, stitching the two operations together into a single .htaccess file?

Download the .htaccess file from your web server to your computer. Open it in your text editor of choice and simply copy the code onto a new line. Save it and upload it to the server, overwriting the one that's there.

larryhatch

11:37 am on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK noisy: Done! I copied the line exactly as you gave it and sent it up.

Now I gotta read up on PHP. Should be a real education.
I like the idea of adding php inline in my .html rather that changing all my filenames.
That way I can get my feet wet, without taking a big scary dive.

I would like to put my own (hidden?) visit counters on several pages instead of just one.
Maybe I can display counts discretely, but I'm real unhappy with my present offsite count service.
It's free, and I got what I paid for.

Thanks VERY much to both you and Valder. This will be a real learning experience.
(a good one I hope!) - Larry

flycast

1:34 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



WOW!
So much discussion on such a simple question. The reason I asked the original question is because the host has the ability to upload a .htaccess file shut down for some reason thus killing the possibility of using anything .htaccess related (like php or ssi).

Renaming files: I definitly do not want to rename files unless it is a last resort.
It would:
1) Require client approval.
2) CReate more complexity in the site by requiring the mod_rewrites.
3) give rise to errors in links and require the checking of all those renamed links.

There are some situations where Google will ignore the link if the name of the file requested is not the name of the file returned. I honestly don't know if mod_rewrite creates this kind of problem.

The posting by MrNoisy about using .htaccess to force html files through the php interpeter is the way to go but . . . remember the server won't allow a .htaccess to be posted. That is why I am looking for some non php method that can be accomplished with html tags (a long shot).

valder

2:59 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Unless you do an external redirect (status code 3**), then the redirection is only done internally and there will be no way for people or search engines to know that they're not being served the html-file.