load an html page into/from a php page - php

i have a website that's mostly written in html, but i have to load it into a server that require the first page to be a index.php. How can i do that?
I have my index.html. is there a way to create a index.php that just load the index.html?
i tried
<html>
<head></head>
<body>
<?php include 'index.html'; ?>
</body>
</html>
but won't work.
i heard of get_file or to import header, but i'm clueless, i never used php. how should i do?

You can just rename the file to index.php. It doesn't require that any actual PHP code be in the file, the server's PHP engine will still process the file (pretty quickly too, since there's no server-side code to interpret) and show the HTML.

PHP
<?php
header( 'Location: http://www.redirect-location.com' );
exit();
?>
HTML
<meta http-equiv="refresh" content="1;url=http://www.redirect-location.com">
.htaccess ReWrite
RewriteEngine on
RewriteRule index\.html index.php [NC,R]
or
DirectoryIndex index.php index.html
In order for this to work you need to allow overrides for indexes in the apache config
AllowOverride indexes

Related

Linking resources in php

I have following file structure for my app
/App
/html
404.html
another.html
other.html
/css
main.css
.htaccess
index.php
I am sending other.html file from index.html with readfile().
All html files shares main.css.
index.html looks like this
<html>
<head>
<link rel="stylesheet" href="../css/main.css">
</head>
<body>
link
</body>
</html>
I am running this on XAMPP. With
http://localhost/App
I'm able to retrieve index.html, but when I click on the link I'm getting 404.html, as I wrote another.html and ../css/main.css the server is looking for http://localhost/App/another.html and http://localhost/css/main.css. This leads to messed up CSS in 404.html and index.html
I attempt to solve this by replacing ../css/main.css with css/main.css, but this leads to messed up CSS in 404.html whenever the error is encountered. Another attempt I tried is /css/main.css, but again no luck server is looking for http://localhost/css/main.css.
So, How do I link those file? Is there any configuration available in .htacccess that can say server to look / (root) as /App, so if there is any configuration then I can get everything works perfectly by saying /css/main.css, /html/another.html, and so on? Or any other suggestion?
Here is the video of the problem: https://youtu.be/Qg7K8gOdyW0
Put inside you .htaccess file the following code:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/App/
RewriteRule ^(.*)$ /App/$1 [L,R=301]
in the index.html use next links:
/html/another.html
/css/main.css
Check this out:
https://www.youtube.com/watch?v=oO1AHIOec3c

Server Side Includes putting php in html

I am trying to print the output of php file in HTML using server side includes.
Here is the code of index.html file.
<!DOCTYPE html>
<html>
<body>
<!--#include file="include.php" -->
<h1>This is a Example Of Server Side Includes</h1>
</body>
</html>
Here is the code of my include.php file.
<?php
echo "Hello From PHP\n";
echo "Hello To HTML\n";
?>
Here is the content of my .htaccess file.
Options +Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
All the files located in /var/www/html.
This is the screen shot of while executing index.html.
Does Server Side Includes also work in localhost? if yes How to configure?
And where to put .htaccess file in var/www/html.
If you are using Nginx, an example of how to use SSI (Server Side Includes) is below:
<!--# include virtual="/body.php?argument=value" -->
Nginx SSI Docs
If you're using PHP, you need to have a file with the PHP extension. You cannot use PHP in a file with an HTML extension. Change index.html to index.php
If localhost does support ssi, it wouldn't be supported in an html file. Try changing the name to index.shtml. Also, since your include path is relative, try <!--#include file='...'-->
Or, you could just try what the other answers say, and use php instead.

Is there a way to make an HTML page include php, but not have a .php extension? I want to "include" my headers

Some pages seemingly don't have a .php extension, but they have server-side stuff in them. Or am I completely wrong with that?
Basically, I'd love to have include statements for my header and footer, without having to copy and paste changes into every HTML document, but rather update the one. Can I do this without making the page .php?
What's the best way to include those?
It does not require a .php ending, just include it :)
Yes, make your webserver parse your HTML files as PHP scripts, then you'll be able to add <?php include 'whatever.php'; from your .html files.
Example for Apache:
AddType application/x-httpd-php .html
Why not use .php?
Just create each page like this:
<?php
include 'header.php';
// your code
include 'footer.php';
?>
And create a header.php for the top part of your layout and footer.php for the bottom part.
You could also look at a template engine like smarty.
You could map the file extension html to be executed as php in a .htaccess file in apache
AddType application/x-httpd-php .php .php4 .php3 .html .htm
Maybe unsupported or different (1 and 1 hosted) on your server.
http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype

How to autoload a site through a php file?

Is there a way to use a php file to automatically load a website.
I have a new version of my website, but I want to keep the current version live (with its current domain). I would just like to direct clients/customers to preview the new version but still be able to go to the current site.
For example: They would go to the current site by visiting www.currentsite.com. And to visit the new version they would visit www.currentsite.com/newversion
Both sites are subfolders within the root of my hosting account. How do I achieve this?
Thanks for any help on this question.
You probably want to take a look at .htaccess files:
Assuming your current website is located in /home/user/public_html/current and your new website is in /home/user/public_html/new, you could set up something like this:
RewriteEngine On
# Rewrite every uri that does not start with /newversion/ to the current website
RewriteCond %{REQUEST_URI} !^/newversion/?(.*)$
RewriteRule (.+) /current/$1 [NC,L]
# Rewrite everything else to /new
RewriteRule (.+) /new/$1 [NC,L]
Judging from your post and the fact that you are mentioning multiple folders in a hosting account, there is a pretty good chance you already have something like this setup for your current website.
Take a look in your root folder and see if there is a .htaccess file and start editing away.
If you're looking for a PHP-only solution, you can put an index.php or simmilar file at the root folder of the domain containing:
<?php
header("Location: http://www.currentsite.com/current");
?>
That would enable a redirection from http://www.currentsite.com/ to http://www.currentsite.com/current. The drawback is that you'd have to stick with "current" in your path, so I'd go for the more elegant .htaccess solution.
EDIT
Oh, and if you already have an .htaccess file in the root folder doing similar rewriting tasks, chances are this approach won't work as index.php won't ever be reached. You'd better check for that first.
Or create a simple index.html file in the "/newversion" directory with an iframe.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<body>
<iframe src="/" width="100%" height="100%"></iframe>
</body>
</html>

How to add a default splash screen without the use of .htaccess

I'm looking for a method to suspend access to a website without loosing the old files, by adding a file to the directory but not .htaccess, since the use of .htaccess has been disabled on the specific server. Are there other ways to do this by using php or another method?
rename your www-root directory and add another, empty one.
You have to rename your index.php, create a new one, and add:
<?PHP header("Location: http://disney.com"); // or something ?>
Also, you may want to check Apache's DirectoryIndex directive, the order of the "default page" is defined here. If your server have DirectoryIndex index.html index.php, the html extension is prior to the php, so You can create a file index.html with:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Jump page</title>
<meta http-equiv="REFRESH" content="0;url=http://disney.com"></HEAD>
<BODY>
Jumping
</BODY>
</HTML>
But if You want to "remove" all files recursively, You have to move the whole directory. Another option is to rewrite the url http://yourpage.com/hidden_directory/ to somewhere, but sadly You need .htaccess to do that, if You can't access the webserver's config file. If You can:
<Directory /path/to/dir/>
RewriteEngine On
RewriteRule ^/hidden_directory/$ http://disney.com [L}
</Directory>

Categories