Converting site from .html to .php - php

my site has now become sufficiently large for me to think it's necessary to convert the pages to php pages to help me update it in the future. The problem is: my site has a number of links to it on various websites across the web. Eg these links point to www.example.com/page1.html but the page is now going to be renamed www.example.com/page1.php
How would people get around this problem? Simply redirect the html page to the php page? Are there any alternatives? Does this have any implications for SEO?
Thanks

URL Rewrite: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
More directly to the point: http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html

The least intrusive method is to simply have your webserver treat .html files as PHP files. That way your links can stay intact, and progressively replacing static .html pages with actual php-enabled pages can be done in an essentially transparent method to users.
Remember, there is no such thing as a "PHP script". There are only files that contain <?php ... ?> code blocks, which will get interpreted/executed when the containing file is passed through PHP.
Unless some of your html pages contain SAMPLES of php code that could be misinterpreted as actual code, then there shouldn't be any issues with making run through PHP.
As a minor side benefit, it wouldn't be immediately obvious that your site is running on PHP, as all the urls would say ".html". But then, that's security by obscurity and shouldn't be counted on to be anything in the way of real security.

You can do a 301 redirect (this works fine for SEO), or just rewrite the URLs so page1.html points to page1.php internally.
Both solutions can be done with the .htaccess file (assuming you are using apache as your webserver)

Maybe consider using a tool such as Dreamweaver to manage your website. That way you can easily rename pages and update the links with a few clicks.
:)

As answered by Marc B,
there is no such thing as a "PHP script". There are only files that contain code blocks, which will get interpreted/executed when the containing file is passed through PHP.
i would say that it's true and if you want to absolutely turn your html files into php files simply put <?php before your <DOCTYPE html!> line and then ?> after your </html> line save it and rename it as example.php if it is example.html
if you are windows8 or higher user then click on 'View' in file explorer and then check 'File name Extension'. Now you'll be able to see the extension example.html and many other files extensions like .jpg, .mp3 e.t.c...., This helps you to easily rename exactly like example.php but not example.php.html as .html will not be visible if you are not checked File name Extension.

I would suggest that you use CodeIgniter (kickass php framework).
You can maintain the existing site structure also, by making use of CodeIgniter's URL suffix option .

Related

Make a second url link to the same directory as a different url, without copying the content to a second directory?

I have files in a directory, "w", and I want to have those same files accessible from a different directory.
I have a MediaWiki installation in the directory 'w', creating a short url to link to the url 'wiki'. I have the files in the 'w' directory but it can be accessed from http://example.com/wiki. I want to have a second wiki entirely with the url format of http://example.com/second-wiki.
Since MediaWiki uses the content of files from a database the code never actually needs to change, even the LocalSettings.php. I set up a database system, modified the MediaWiki system, and created multi wiki support in a single database, by using a database table with input information such as the url to use. Or even use the same files and add a localsettings.php file to a directory 'w2' but use everything else from the original directory, 'w'. Is this possible? Preferably using .htaccess, or some other equally easy to edit. I don't want any changes to php configuration though.
I believe this may help...... - it is a simple redirect done in PHP so it is easy to edit later, etc.
I'll work with the fact you have a 'w' directory accessed by http://example.com/wiki and you want to access that through http://example.com/second-wiki (where 'magic' will be done to actually open the other URL).
In the 'w2' folder, make an index.php file with the following contents:
<?php
header("Location: ../w");
// NOTE: you may need to make that w/index.php or other pointer
exit();
Now, any time you access http://example.com/second-wiki, you will actually see http://example.com/wiki
Simple and easy to change later if you need to!
Not sure from the question that this is the solution (it fits the topic and some of the question text, though the question text does 'jump around' a bit...) - if it isn't, please rephrase the question to be more clear on just what you are looking for (in one place you say "the code never actually needs to change, even the LocalSettings.php" - then in another you talk about needing separate settings.....) - however, if you are looking for the 'simplest' (IMHO) way to make multiple URLs point to the same folder, this is the way to go - pure PHP and easy to mod later!

Include HTML files in a PHP wrapper

I don't know how to put this better and tried search some around but I wasn't really sure on what to search either for my situation.
I'm in the unfortunate situation of managing a very old website, that has been passed by the hands of at least 5 webmasters.
The whole site is built of several hundreds of pages, each made of a single .html file; there is no controller logic or anything.
Now I need to implement a couple of scripts globally throughout the site, and I was wondering if there is a quick and dirty way to accomplish this.
I was thinking to encapsulate every request through a sort of rudimental PHP controller that simply read the requested file, require it in the script and render it with the same exact content and URL, but with the necessary scrpts included before the closing </body> tag.
Unfortunately I'm quite a novice in this, and I'm afraid also to allowing some bad injection from external sources. What is the best way to achieve something like this? I'm on a linux apache server.
Here are two approaches:
1) PHP Wrapper
Along the lines of what you're asking for, you can use your web server redirect all incoming HTML requests to a PHP file that does the following:
Takes a reference to the HTML file
Opens and reads the file in to a string
Makes the changes
Outputs the modified content in the response
If you are using a server like Apache httpd you can use mod_redirect to handle redirection of the requested URL to your PHP file.
This approach is a bit inefficient since for each request the HTML content needs to be read and modified. The approach below of editing the files will be higher performance.
2) Edit HTML Files
You can write a script to go through all the .html files and programmatically edit them.
One implementation to do this would be to open each file and add some lines at the tome and some others near the bottom. A the top of each file you could add a require() for your PHP file:
<? php
require('path/to/myinclude.php');
?>
At the bottom of the HTML before the </body> tag, call your function in the myinclude.php file, for example:
....
<?
my_footer_function();
?>
</body>
</html>
Depending on your webserver, you may be able to have the PHP interpreter execute for the .html extension so you don't have to change file extensions, if that's your wish.
This way, after this edit, you can modify all the behavior in the my_footer_function() in all your files simply by changing the one myinclude.php.

Serving different XML content on the same web

I don't know if this is the suitable place to ask this question, so I am sorry if I am doing it wrong. I think this is not a duplicate question. If it is, I am sorry too.
Currently, I have a web app which takes its content from a unique XML document. The URL is "http://webapp.com/"
The problem is that now I have to create a second version of the web which uses a new different XML document, so I have to put them different URLs, something like the following:
http://webapp.com/activities
http://webapp.com/stages
How can I have all my sources on just one directory on server-side (I suppose it's better to maintain, the resources are cached better, etc...) but with these 2 URLs pointing to the folder and making the PHP loades the XML depending on the URL?
I suppose I have to change the .htaccess file to redirect to that folder, but how can I tell what XML I must load? And the user must see on the search bar the URL he used, for example "http://webapp.com/activities"
Can anybody help me please?
Thanks for all
You can use a .htaccess rule to redirect a URL like http://webapp.com/{anything} to http://webapp.com/?q={anything}. Then in your script you can write conditions based on $_GET['q'] and load different XML. That is if I understand your question right.

Designing a content delivery system using PHP

Currently, I have a system that actively generates the pages on my site using PHP, more or less like so:
index.php ------include(query.php);-----> query.php grabs content from a file that corresponds to index.php
Query.php simply assembles the page from the mentioned index.php file and from header, footer, and navigation files.
The index.php file acts as a sort of proxy or label if you will so that when users visit the site, instead of having urls like "query.php?page=index" they have real pages.
The issue of course is that this is a bit convoluted. For each page of the site, I need 2 files: the "wrapper" file (such as index.php) and a content file to which it corresponds. I'd like to only be using a single file. The issue is that the single file should only contain the content of the page - not structure, header, footer etc.
So, what I'd like to be able to do is to be able to have index.php contain ONLYand a paragraph for example. When it is accessed, somehow PHP kicks in and applies a template and the header and footer.
Is PHP too high level a language to be able to do this? I know it is often done with Tomcat and java servlets, but I thought it would be cool to do with PHP.
EDIT: Important point, I don't want to use GET variables.
It's a bit hard to tell what you're trying to do, but have you looked into using a framework such as Kohana or Synfony? This will do pretty much exactly what you're asking.
If you're looking for a good template system, I suggest PHPTAL.
Failing that, it doesn't sound like you need to do anything that special. On the index.php page, why not just include header.php, the content, and footer.php? Short of using auto_append_file and auto_prepend_file, you can't add content to the page that is not explicitly in the code.
It sounds like what you want to do is route all requests through a single point (like frameworks do). Let's call it main.php.
On main.php you would have:
include header.php
include $_SERVER['PATH_INFO'] . ".php" //Requested file from URL. TODO handle this better
include footer.php
Then you would route all requests (using your server configuration) to "/main.php/pagename." Then pagename would only need its respective content.

display one page from a site on a different domain name

I have a site complete with CMS etc all working under one domain name. It turns out for legal reasons one page on this site has to sit on a different domain name. The page is hooked into the same CMS as the rest of the site (built using codeigniter). I don't want to have to do another installation just for this page.
Is there any simple way to display just this page under a different domain name without taking it out of the current application?
Thanks a lot
You should look at either (in order):
an include()with correct php.ini configuration
a file_get_content() and printing the variable into your page
an <iframe src="yoururl"> wich would be the easy peasy but unsafe way
using the on-purprose curllibrary
using fopen() wich theorically allows distant files to be opened, but based on my experience, it's not that reliable
Look at this site, it seems rather exhaustive regarding your problem.
Try including the file
<?php include 'http://www.domain.com/url/to/file/page.html' ?>
I think what you need here is a symlink, which is something I don't know too much about. My understanding is that the path displayed to the user does not in fact have to have anything to do with where the file is actually stored, meaning you can set this up to have a completely different URL while keeping it as part of your original application.
A simpler thing is doing a redirect...it's one line of code in your .htaccess file and you're good to go.
include is a possible solution depending on the format of the remote page (ie, this won't work very well if the remote page has a full DOM structure, and you're trying to include the remote page within the DOM structure of your CMS page), however more information about that remote page would be needed to help determine if include() alone would be enough.
Regardless, if include() does, work, you must make sure allow_url_include in php.ini is enabled, as by default script execution will terminate when encoutering a remote URL include statement.

Categories