Default file for Apache localhost - php

I have apache2 installed. When i type http://localhost it goes to a file http://localhost/class/index.php . How do i change it to say http://localhost/index.html or any other page? Which file will I find the setting to do this? Thanks!

Find the DirectoryIndex directive in your Apache configuration file (httpd.conf) or add it to a .htaccess file and change it to look like this if you want to limit your default index file to just index.html:
DirectoryIndex index.html
You can also include more resources and they will be used in the order given, e.g
DirectoryIndex index.html index.php
would display the index.html file first if both index.html and index.php existed.
Don't forget to restart Apache if you made the change to the httpd.conf file.
Look at the mod_dir documentation for more information.

Apache will not trigger HTTP redirections unless you instruct it to do so.
My advice is that you open your favourite text editor and search for the class string in the following locations:
*.conf files inside the Apache installation directory.
.htaccess files inside your HTML directores.
If that fails to find anything, you could also search for header() calls in your *.php code.

Related

EasyPHP default load page

I've noticed that when I access local web the default index.php file in the www folder doesn't show, and when I open a folder it automatically opens the file with name index.html, anyone knows why that is happening? (I'm using EasyPHP 1.8 because it's the version we're using in high school).
Thanks!
It depends on the web server configuration you're using.
Set in apache2 configuration file (for example in Ubuntu 16.04 /etc/apache2/apache2.conf) or in .htaccess file (that will give priority to .php file over .html file):
DirectoryIndex index.php index.html index.htm
or simply:
DirectoryIndex index.php

How to auto redirect IP address to a login PHP script?

I am using WAMP server, and I am a novice.
Currently, I have many scripts under /www/mySite.
I have set /www/mySite as my default location for the wamp server.
However, when you set the browser address to http://myIPAddress, it automatically shows a list of files under /www/mySite.
I don't want this. When the user points to http://myIPAddress, I want it to point directly to http://myIPAddress/main_login.php. How do I achieve this?
The simplest way is to rename your main_login.php to index.php
You can also do it using your server configuration or .htaccess
You may include another index.php and use its header like this
<?php
$redirection_url='main_login.php';
header('Location: '. $redirection_url);
?>
Change the name of main_login.php to index.php (index.* is something apache reads as default page) or learn about .htaccess and redirect "/" (which is root of your webserver) to main_login.php
Basically there are two ways:
Changing the Apache configuration file an telling Apache to look up all the main_login.php file (by default it gets all the index files)
Changing the name of your file from main_login.php to index.php
Changing Apache configuration file
To change the Apache configuration file you must
Go to the httpd.conf file
Look for the DirectoryIndex row line
Edit it as you wish
Restart Apache
Renaaming your file
It's the simplest and best way.

How to call index.php on startup

I get my web site appears only by typing the following: www.example.com/index.php
when typing: www.example.com nothing happens.
How to call index.php on startup by typing my website's address.
Create a .htaccess file and put it in your server root. Add the following to the file:
DirectoryIndex index.php index.html index.htm
In the server section of your nginx.conf (or whatever file it includes), make sure you have the line:
index index.php;
You ARE running nginx, aren't you? ;-)
While you have not provided any technical details on your web server, I would suggest looking into DirectoryIndex.
The DirectoryIndex directive sets the list of resources to look for,
when the client requests an index of the directory by specifying a /
at the end of the directory name. Local-url is the (%-encoded) URL of
a document on the server relative to the requested directory; it is
usually the name of a file in the directory. Several URLs may be
given, in which case the server will return the first one that it
finds. If none of the resources exist and the Indexes option is set,
the server will generate its own listing of the directory.
Example:
DirectoryIndex index.html index.php
A request for http://mysite.com/docs/ would return http://mysite.com/docs/index.php if it exists, or would list the directory if it did not.

Hide open directory

I have a website and right now users can just open a directory and see all files in it. How do I disable that?
I was thinking about the php.ini file, or generally any php configuration that might do the trick (it is an Apache server run with PHP).
Disable Indexes option in apache configuration.
Put this either in your httpd.conf or .htaccess in the root of the site.
Options -Indexes
This way, if the folder does not have an index page, the user will get a 403 Forbidden error.
Put a text file named .htaccess to your root-dir of your website or the dir you want to hide with following content:
Options -Indexes

htaccess downloading file instead of loading

I would really like my index.html to be able to have a PHP script work on it. I read that you can do this through the htaccess file. I only have access to a subdomain website directory, where I can upload my files through FTP.
The directory did not have a htaccess file, so I created one using notepad: .htaccess and added this to the file:
AddType application/x-httpd-php .html
The problem is, instead of loading the index.html page, it downloads it as a file...would I need to add something extra to the htaccess file? :S
You don't need to name the file index.html to have it served by default. You can change the default document using your with an entry in your .htaccess file like this:
DirectoryIndex index.php
Then when you navigate to http://yoursubdomain.example.com you will be served index.php instead of index.html.
If really do want PHP to interpret your .html documents then the entry you had in your question will work when PHP is running as an Apache module. If your host is running PHP as CGI, you want:
AddHandler application/x-httpd-php .html
If it still doesn't work, then this web page has some more suggestions:
http://www.velvetblues.com/web-development-blog/how-to-parse-html-files-as-php/
The directive you have sets the content-type of files with a .html file extension.
If the server has PHP installed and enabled, that content-type will cause it to be run though the PHP engine and then the output from that sent to the client.
If it doesn't have PHP installed, then the file will just be served up to the client with that content-type. Since browsers don't handle PHP scripts themselves, they will then just save the file.
You need to install and enable PHP as well as setting the content-type.
Presumably your hosting is supporting PHP?
If so, then you need to rename your file from index.html to index.php

Categories