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>
Related
Given the following index.html file:
<html>
<body>
<p>Welcome to <?= $_SERVER ['HTTP_HOST']; ?></p>
</body>
</html>
I expect to see "Welcome to EXAMPLE.COM", All I see is "Welcome to ".
What would cause this to happen if the code checks out?
Your file is named index.html. Unless you told your server that .html files should be treated as PHP scripts, that means the PHP code is NOT being executed - it's going out as literal text. And since PHP tags make it look like HTML, your browser is properly hiding that unknown/illegal tag.
Rename it to index.php.
It's not running because that part is not html (it's php) but you have saved it as an html file instead of as a php file.
rename it to index.php and try again?
Web servers are usually configured to run PHP only on files with the .php extension. Your index.html file will be passed as-is to the browser, which will probably ignore the unknown PHP tags. If you take a look at the source code of the web page, the tags will probably be there.
If you must have a .html extension, you can usually configure the web server to run PHP on .html files. For example, in Apache, you can use the AddType directive in an .htaccess file or in the server configuration (httpd.conf):
AddType application/x-httpd-php .html
However, this will run PHP on all .html files (in that directory), which may put an unnecessary load on the server.
A much better way is to use URLs without extensions. In Apache, you can use the DirectoryIndex directive to specify a list of index files that the web server will search for:
Options +Indexes
DirectoryIndex index.html index.php
When a browser requests a URL that ends with a slash, such as http://mydomain.example/foo/, the server will search for foo/index.html or foo/index.php in the DocumentRoot (or, failing both, generate a directory listing). You can now use whichever type of index file is appropriate for the moment, without ever having to change your URLs.
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
Every sub directory inside the directories 'application' and 'system' in my codeingiter web application has an index.html file. Inside this HTML file there is what looks to be a standard error message. It contains this code:
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>
I assume these are created so that if anyone tried to visit a directory inside either 'application' or 'system' it wouldn't list all the files, but would instead show an error.
These seem redundant though as I have added an .htaccess in each directory to deny all access. Every PHP file in those two directories also has the first line:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Which should mean that no one can view any of those files at all (as I am protected once by the .htaccess and once by that line of PHP).
Therefore my question is - in the interest of keeping my web application organised and clutter free, can I safely remove these index.html files? Will this cause any bad side effects to my codeigniter web application?
Thanks in advance
Yes, you can remove them.
but even if you have proper rights in place, you should have them there. as they are there on only purpose, in case, you forgot to implement proper directory browsing rights
as far as you set your .htaccess file,, which is not redirecting towards or have no relation with your index.html file, you are safe (and no use to keep) to remove your index.html. But you should be careful. index.html can help in case if you fail with your .htaccess
In general You can remove those index.html files but you need to be sure that directory index is disabled in you web server configuration.
For Apache web server you can use Options -Indexes either in global configuration or in .htaccess files like this:
<Directory /wwwdata/ >
#disable directory index
Options -Indexes
#other options ...
</Directory>
Those index.html files in CodeIgniter prevent (in any case) directory listing wich can lead to serious security flow.
While I agree that a .htaccess and the basepath condition checks are good enough, I do not really think that having two html files in two directories really clutters anything. You can never be careful enough when putting things on the web, and the CodeIgniter guys sure would have thought about it before adding it.
I really do not see any value addition removing them, but if that is what you want to do go ahead.
But I suggest keeping index.html as well. Keeping index.html wont harm your application but sure it do some sort of protection.
If you say that you have forbidden access to the directory with .htaccess then you can safely remove them and let your worries go away!
But in case the directory is used by PHP script for some reasons and puts something in those directories and then provides a link to a user, just for example, than it will not work properly and you will have to remove your .htaccess restrictions.
I would just recommend to leave just a blank index.html and when a user reaches the directory there will be just a blank page displayed.
Or you could force a user to be redirected to the main page with index.php, for example:
<?php
header("Location: ../");
?>
I am creating a file hosting website. I would not like people to access the directory
public_html/quick/files
unless they have a direct download link from uploading a file. How would I go about this?
For others: To rephrase, deny permission to index all the files.
Create a file named .htaccess in public_html folder with this content:
Options -Indexes
Creates a blank index.html file in the directories.
If thought necessary, create a redirect to an error page.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=<URL_ERROR_PAGE>"></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>
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>