How to call index.php on startup - php

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.

Related

Loading a HTML page from webfoot folder of apache server - newbie

As the tittle says I'm new to all concepts of networkiing and web development.
Yesterday I was able to set up a Local Apache Server which I am using for development testing purposes.
I have assigned for a Server the ServerName "client1.dev" with a VirtualDocumentRoot "/www/client1/wwwroot", yet it is unclear for me how I am supposed to link my HTML page.
I am currently stuck at the point where all my files when accessing the domain appear under a plain list format from which I can select my files which will eventually load the HMTL content of choosing.
Since I'm a total beginner in this domain and I've got a hard time even googling the right questions. I'd like to know how I could instantly when accessing the server name domain to load a given HTML page.
By default, the Apache HTTP server will look for a file named index.html in the directory that is displayed. If it finds such a file, the index.html will be displayed. Otherwise it falls back to list the contents of the directory (but that could be changed to disallow directory listings).
If you do not have an index.html file in the directory, the easiest solution would be to create one.
If you want to display another file by default, then you can change that in the Apache configuration. Use the DirectoryIndex directive to do that. A basic example that changes the index files for the /foo directory looks like this:
# Example A: Set index.html as an index page,
# then add index.php to that list as well.
<Directory "/foo">
DirectoryIndex index.html
DirectoryIndex index.php
</Directory>
# Example B: This is identical to example A,
# except it's done with a single directive.
<Directory "/foo">
DirectoryIndex index.html index.php
</Directory>
The default page you want to make appear when accessing the root directory in your browser should be named "index.php" (I am supposing you are running PHP)

Filezilla folder

I have created a website and I already bought the domain and the host. Now I'm trying to upload my website (in the folder "Mywebsite" ) To the server via Filezilla.
In my folder "Mywebsite" I have index.html, faq.html, contact.html and other things.
I uploaded the files on the server, in the folder called public_html. Now if I go to check my website, I can see this folder menu here.
Now if I click the "index", I can see my homepage of the website ( but this should happen when I open my website, right? ) or if I add /index.html in the url. Anyway that's my problem. I just want to know how to set the page index.html when I open www.mywebsite.com.
You can use Apache's DirectoryIndex directive, for example:
<IfModule dir_module>
DirectoryIndex index.html index.htm index.xhtml index.php index.php3 index.php4 index.php5 index.phtml
</IfModule>
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.

Avoid Directory listing in a shared server

I am using shared server for my website and therefore i dnt have access to my httpd.conf.
my director r getting listed like
when i click on mysite.com/xyz/
all php files are showing.
Please help
in your .htaccess file add
Options -Indexes
To follow up and more thoroughness, you can also use an index file in the directory by creating a blank index.html file.
e.g. index.html
Or you can also specify the exact file and orders you want to be the index in htaccess with
DirectoryIndex index.html index.php
So there you have a few choices. The file will have to exist and it can contain anything or nothing.

Default file for Apache localhost

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.

setting home (default) page in a directory

It's been a while since I created a new directory on my domain (call it my/domain/dir3). I have others, each containing a index.php (dir1/index.php - dir2/index.php), each index is called if the directory URL is called (thus a URL of my/domain/dir1 will call my/domain/dir1.index.php).
No the embarrasing part ... I've completely forgotten how I did this! ... blank .... nothing ... no recollection. Please somebody enlighten me.
If you use Apache, it does this automatically. You can tweak the settings in httpd.conf though.
Well if it's a standard Apache/PHP installation then putting an index.php file in the directory would make it the default page in a directory.
Oh, if you want a different file to be the index. Create a .htaccess file in the directory and enter this:
DirectoryIndex index.html index.htm index.php something.php
Replace something.php with the file you want and presto ;). You can't have two indexes.
If index.php is seen by Apache as the default index file, my/domain/dir1/ will see my/domain/dir1/index.php. If you want something more complex, You'll need mod_rewrite.

Categories