|
Posted by Ed Mullen on 11/12/07 15:02
Jonathan N. Little wrote:
> Ed Mullen wrote:
>> Ed Mullen wrote:
>>> Jonathan N. Little wrote:
>>>> Ed Mullen wrote:
>>>>> 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
>>>>
>>>
>>> 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)?
>>
>
> 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
[Back to original message]
|