PHP include and changing page names

E

Ed Mullen

I'm considering using PHP to include the menus on my Web pages. I've
tested it and it works fine (even though I know next to nothing about
PHP). My understanding is that the page that will import content using
a PHP include must have a .PHP extension. Which means that all my page
names (which now end in .html) will change. Which means that the search
engine results will point to non-existent pages.

Any thoughts on what I might do about this dilemma?

--
Ed Mullen
http://edmullen.net
http://mozilla.edmullen.net
http://abington.edmullen.net
Why are there interstate highways in Hawaii?
 
S

Safalra (Stephen Morley)

I'm considering using PHP to include the menus on my Web pages. I've
tested it and it works fine (even though I know next to nothing about
PHP). My understanding is that the page that will import content using
a PHP include must have a .PHP extension. Which means that all my page
names (which now end in .html) will change. Which means that the search
engine results will point to non-existent pages.


Does your host allow you to use .htaccess files? If they do, you can either
allow PHP to process .html files, or use URL rewriting. If using the second
option, consider rewtiting URLs to end with a slash and then internally map
to the correct script - this hides the technology from the user and allows
it to change at a later date without complication.


If you can't use .htaccess, one trick to to take advantage of the rules
most servers use by default, and for each URL of the form:

http://www.example.com/somewhere/something.html

....replace the HTML file with a PHP file here:

http://www.example.com/somewhere/something.html/index.php

....where 'something.html' is now a directory.
 
D

dorayme

Ed Mullen said:
I'm considering using PHP to include the menus on my Web pages. I've
tested it and it works fine (even though I know next to nothing about
PHP). My understanding is that the page that will import content using
a PHP include must have a .PHP extension. Which means that all my page
names (which now end in .html) will change. Which means that the search
engine results will point to non-existent pages.

Any thoughts on what I might do about this dilemma?

On servers that you can control, you can make them check and
process for php on .html ages, either directly in config files or
via .htaccess. On servers that you do not control or do not allow
..htaccess control of this, you can ask the server admin to fix it
so that all your .html files are scanned for php.

If they will not allow this (there are some downsides, one being
servers have to work harder and less efficiently, not all html
files have php and it is wasting its time) you can ask them to
redirect all .html files to php mirror files which you can make
and put on the server to avoid having to upset already bookmarked
html files etc.

All these options I have done for different sites and purposes.
On one, I just have decided to use .php and be done (simple!).
 
J

Jonathan N. Little

Ed said:
I'm considering using PHP to include the menus on my Web pages. I've
tested it and it works fine (even though I know next to nothing about
PHP). My understanding is that the page that will import content using
a PHP include must have a .PHP extension. Which means that all my page
names (which now end in .html) will change. Which means that the search
engine results will point to non-existent pages.

The include file doesn't but the calling file may for it to parse PHP,
server settings dependent.

<!-- caller.php -->
<?php include_once('fileWithPhpCode.txt');
....

But it is advisable to make the include file fileWithPhpCode.php so if
some hacker call your file directly they will only see the html output
not the php source.
Any thoughts on what I might do about this dilemma?

Very simple example...
..htaccess file

RewriteEngine On

RewriteRule ^(.*)\.html$ $1.php
 
E

Ed Mullen

Jonathan said:
The include file doesn't but the calling file may for it to parse PHP,
server settings dependent.

<!-- caller.php -->
<?php include_once('fileWithPhpCode.txt');
...

But it is advisable to make the include file fileWithPhpCode.php so if
some hacker call your file directly they will only see the html output
not the php source.


Very simple example...
.htaccess file

RewriteEngine On

RewriteRule ^(.*)\.html$ $1.php

Excellent. Thank you all. I do have the ability to edit the .htaccess
file. I will go read more so as not to be quite as dangerous as I am now.

--
Ed Mullen
http://edmullen.net
http://mozilla.edmullen.net
http://abington.edmullen.net
Introducing LITE - the new way to spell LIGHT with 20% fewer letters!
 
E

Ed Mullen

Ed said:
Excellent. Thank you all. I do have the ability to edit the .htaccess
file. I will go read more so as not to be quite as dangerous as I am now.

Well, that was interesting.

Using the above RewriteRule I did a test. And the only way it works is
if I rename the calling .html file to .shtml. Which, obviously, defeats
the purpose.

Is this something that can configured/over-ridden using the .htaccess
file? Or is it at the server configuration level (which I do not have
access to)?

--
Ed Mullen
http://edmullen.net
http://mozilla.edmullen.net
http://abington.edmullen.net
There are a number of mechanical devices which increase sexual arousal,
particularly in women. Chief among these is the Mercedes-Benz 380SL.
 
D

dorayme

Ed Mullen said:
Is this something that can configured/over-ridden using the .htaccess
file? Or is it at the server configuration level (which I do not have
access to)?

Server admins can block all your attempts. I had a case of this
recently and the Uni concerned offered the back-up plan I
mentioned in my previous post (to direct all .html to mirror .php
ones)...
 
J

Jonathan N. Little

Ed said:
Well, that was interesting.

Using the above RewriteRule I did a test. And the only way it works is
if I rename the calling .html file to .shtml. Which, obviously, defeats
the purpose.

Is this something that can configured/over-ridden using the .htaccess
file? Or is it at the server configuration level (which I do not have
access to)?

Could be the way they have the server setup. Obviously PHP is more
server intensive that HTML so they may no wish for you to have a blanket
conversion. There is another way maybe. Since you have access to the
..htaccess file then you should be able to setup a custom ErrorDoc.
Point your 404 Errors to a PHP script.

#.htaccess
ErrorDocument 404 /scripts/404.php


It is what I do in my site in my signature, It does a bit more to help
me log bad links and hacking attempts but basically you can do this with
your 404.php script:

Get the request URI $requested=$_SERVER['REQUEST_URI'];

make a hash (associative array) of all your obsolete pages "HTML" with
values the new PHP page. Here im semi-pseudocode:

IF the hash has the $requested as a key
{

$newPage = $myChanges[$requested];

then redirect with the script

header("HTTP/1.1 301 Moved Permanently");//inform it is permanent change
header("Location: $newPage" );
}

ELSE
{
Display your custom 404 message because this is a bad URL not and
obsolete one.
}


You might be able yo get around the restriction this way and it can be
just as transparent to the users.
 
E

Ed Mullen

Jonathan said:
Ed said:
Well, that was interesting.

Using the above RewriteRule I did a test. And the only way it works
is if I rename the calling .html file to .shtml. Which, obviously,
defeats the purpose.

Is this something that can configured/over-ridden using the .htaccess
file? Or is it at the server configuration level (which I do not have
access to)?

Could be the way they have the server setup. Obviously PHP is more
server intensive that HTML so they may no wish for you to have a blanket
conversion. There is another way maybe. Since you have access to the
.htaccess file then you should be able to setup a custom ErrorDoc.
Point your 404 Errors to a PHP script.

#.htaccess
ErrorDocument 404 /scripts/404.php


It is what I do in my site in my signature, It does a bit more to help
me log bad links and hacking attempts but basically you can do this with
your 404.php script:

Get the request URI $requested=$_SERVER['REQUEST_URI'];

make a hash (associative array) of all your obsolete pages "HTML" with
values the new PHP page. Here im semi-pseudocode:

IF the hash has the $requested as a key
{

$newPage = $myChanges[$requested];

then redirect with the script

header("HTTP/1.1 301 Moved Permanently");//inform it is permanent change
header("Location: $newPage" );
}

ELSE
{
Display your custom 404 message because this is a bad URL not and
obsolete one.
}


You might be able yo get around the restriction this way and it can be
just as transparent to the users.

Jonathan, thanks. This is obviously going to take more education and
research on my part to sort out. Since I have an eye exam in an hour,
and my pupils will be dilated for several hours, I probably won't be
doing much computing the rest of the day!

--
Ed Mullen
http://edmullen.net
http://mozilla.edmullen.net
http://abington.edmullen.net
There's only two things that money can't buy and that's true love and
home grown tomatoes. - Guy Clark
 
E

Ed Mullen

dorayme said:
Server admins can block all your attempts. I had a case of this
recently and the Uni concerned offered the back-up plan I
mentioned in my previous post (to direct all .html to mirror .php
ones)...

It's not so much that they're blocking anything, it's that, in order for
the RewriteRule to work, they are requiring the files have an .shtml
extension. And what I'm trying to accomplish is:

1. Not destroy bookmarks people have set to my pages (all currently
with .html extensions)
2. Not destroy references the search engines have already indexed to my
pages (ditto).

I need to more thoroughly investigate and understand Jonathan's
suggestions when I have the time.

Thanks!

--
Ed Mullen
http://edmullen.net
http://mozilla.edmullen.net
http://abington.edmullen.net
In love the paradox occurs that two beings become one and yet remain
two. - Erich Fromm
 
J

Jonathan N. Little

Ed said:
Jonathan, thanks. This is obviously going to take more education and
research on my part to sort out. Since I have an eye exam in an hour,
and my pupils will be dilated for several hours, I probably won't be
doing much computing the rest of the day!

Yeah but everything is gonna look so coooooool! Have fun.
 
M

mbstevens

Ed said:
I'm considering using PHP to include the menus on my Web pages. I've
tested it and it works fine (even though I know next to nothing about
PHP). My understanding is that the page that will import content using
a PHP include must have a .PHP extension. Which means that all my page
names (which now end in .html) will change. Which means that the search
engine results will point to non-existent pages.

Any thoughts on what I might do about this dilemma?
In addition to the others' thoughts about server configuration,
I would suggest you also consider preprocessing. This won't work
on all sites, especially those that require re-writes from data bases
on the fly. But if you have mostly static pages with common menus,
preprocessing works very well. Your page names remain the same. You just
run the preprocessor on a local machine and upload the pages with FTP.
 
B

BootNic

Ed said:
Jonathan N. Little wrote: [snip]
Very simple example...
.htaccess file

RewriteEngine On

RewriteRule ^(.*)\.html$ $1.php

Excellent. Thank you all. I do have the ability to edit the
.htaccess file. I will go read more so as not to be quite as
dangerous as I am now.

Well, that was interesting.

Using the above RewriteRule I did a test. And the only way it works
is if I rename the calling .html file to .shtml. Which, obviously,
defeats the purpose.

Is this something that can configured/over-ridden using the .htaccess
file? Or is it at the server configuration level (which I do not have
access to)?

You could try to use RedirectMatch in your .htaccess:

RedirectMatch 301 (?i)^(.*)\.html(.*)$ $1.php$2
 
J

Jonathan N. Little

BootNic said:
(?i) is case-insensitive matching


Ah! Unfamiliar with that one. But what good would case-insensitive
matching do when you are passing the basename through? Somefile.php
SomeFile.php, and SOMEFILE.php won't works if the file name is somefile.php

I would think case-insensitive matching would be useful is you are not
parsing the name

RedirectMatch 301 (?i)^THISFILE.HTML$ thatfile.php
 
E

Ed Mullen

mbstevens said:
In addition to the others' thoughts about server configuration,
I would suggest you also consider preprocessing. This won't work
on all sites, especially those that require re-writes from data bases
on the fly. But if you have mostly static pages with common menus,
preprocessing works very well. Your page names remain the same. You just
run the preprocessor on a local machine and upload the pages with FTP.

But, wouldn't that mean that the HTML that I want to include using PHP
would then be physically present in all the html files? Or am I
misunderstanding?

--
Ed Mullen
http://edmullen.net
http://mozilla.edmullen.net
http://abington.edmullen.net
All that glitters has a high refractive index.
 
B

Bergamot

Ed said:
But, wouldn't that mean that the HTML that I want to include using PHP
would then be physically present in all the html files?

The purpose of a preprocessor is to combine all the page parts into a
whole static page prior to uploading it to the server, instead of having
the server combine them. Whether this is a good idea for your site
depends on how large the site is and how often common code changes.
 
E

Ed Mullen

Bergamot said:
The purpose of a preprocessor is to combine all the page parts into a
whole static page prior to uploading it to the server, instead of having
the server combine them. Whether this is a good idea for your site
depends on how large the site is and how often common code changes.

As I thought. Thanks.

--
Ed Mullen
http://edmullen.net
http://mozilla.edmullen.net
http://abington.edmullen.net
If you can't be kind, at least have the decency to be vague.
 
M

mbstevens

Ed said:
But, wouldn't that mean that the HTML that I want to include using PHP
would then be physically present in all the html files? Or am I
misunderstanding?
Yes. Space is usually not a problem, since the extra code is only a K or less
per file. The time it takes to serve the page is also not a problem,
since no program except the server itself is called to serve the page.

An example of the kind of site a preprocessor would -not- work for would be
newegg.com. On a site like that, you're pulling little bits and pieces of
information from all sorts of places to generate a page.
But if your pages are mostly static, a preprocessor is a good way to
do things.

http://www.htmlhelp.com/links/preprocessors.html

....has a nice selection. Or just write your own for your special needs.
It doesn't take a lot of effort.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top