Php script directory index

Guide – Usage of DirectoryIndex in Apache/2 with (.htaccess) File

DirectoryIndex used to allow you to land default page when client access a directory. For example, When a visitor request a directory to access it on your website, you can define the file to load when they request to a directory. To display a “index.html” file instead of “index.php” when client request a directory . Simply we can create a .htaccess file on our root directory or any other location.

Setup index.html as a default page when directory accessed

#vim /var/www/html/.htaccess DirectoryIndex index.html 

Here we have define default page “index.html” to load if client request “/web” directory.

We can also define multiple file to load default if client access “/web” directory.

Setup multiple file as a default page when directory accessed

#vim /var/www/html/.htaccess DirectoryIndex index.html index.php index.shtml 

You can see I have define DirectoyIndex first load default page “index.php” than “index.php” and so on.

If client request a directory web server try to load first “index.html” file. If “index.html” file is not available on the accessed directory, than web server try to load next define file “index.php” and so on.

Читайте также:  Python requests get params dict

If non of them files are available on directory. Apache server try to revert it’s default setting and it will display an error message like “ 403 Error-Forbidden! ” . If you get this error that means Indexing is not allowed on your web server.

Here you can see my vhost configuration file for example.

 ServerName www.example.com DocumentRoot /var/www/html CustomLog /var/log/httpd/vhosts/www.example.com/access_log combined ErrorLog /var/log/httpd/vhosts/www.example.com/error_log Options -Indexes -MultiViews +FollowSymLinks #AllowOverride None AllowOverride All #AllowOverride AuthConfig Limit FileInfo Order allow,deny Allow from all DirectoryIndex index.html DirectoryIndex index.html index.php index.shtml Deny from all   

After editing your Apache configuration file you will need to restart/reload Apache service.

# service httpd reload OR # service httpd restart

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Chansig / DirectoryIndex Public archive

Directory Index — The simplest PHP directory Index

License

Chansig/DirectoryIndex

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Directory Index — The simplest PHP directory Index

Directory Index is a simple PHP script that lists the contents of any web-accessable directory and allows navigating there within. Simply upload index.php file to any directory and get immediate access to all files and sub-direcories under that directory. Directory Index is written in PHP 5.3+ and distributed under the MIT License.

  • Extremely simple installation
  • Creates on-the-fly listing of any web-accessable directory
  • Custimizable sort order of files/folders
  • Easily define hidden files or file type to be excluded from the listing

Directory Index requires PHP 5.3+ to work properly. For more information on PHP, please visit http://www.php.net.

  • Upload src/index.php to the folder you want listed. That’s all!
  • For more settings:
    • copy src/index.php or execute src/generate.php with the destination in argument and rename index.php.dist in index.php. ex:
      php src/generate.php /var/www/mysite
    • Edit the new index.php and change values in Setting class
    • Upload index.php to the folder you want listed.

    Ensure you have the latest version of Directory Index installed.

    Verify that you have PHP 5.3 or later installed. You can verify your PHP version by running:

    Find a problem or bug with Directory Index? Open an issue on GitHub.

    Directory Index is distributed under the terms of the MIT License.

    About

    Directory Index — The simplest PHP directory Index

    Источник

    PHP: Get current directory index file name

    I must not be phrasing this question right because I couldn’t find an answer to this but surely it’s been asked before. How do I get the current filename from a URL if it’s the directory’s index file? I.e. This will get index.html if I’m on www.example.com/index.html

     $url = basename($_SERVER['REQUEST_URI']); 

    But that won’t work if i’m on www.example.com. The only thing I’ve come up with so far is something like this:

     $url = basename($_SERVER['REQUEST_URI']); if($url == "")

    But that’s obviously a bad solution because I may actually be on index.htm or index.php. Is there a way to determine this accurately?

    4 Answers 4

    $_SERVER[‘SCRIPT_FILENAME’] will determine the full path of the currently executing PHP file. And $_SERVER[‘SCRIPT_NAME’] returns just the file name.

    This is one of the other methods.

    $url = basename($_SERVER['REQUEST_URI']); $urlArray = explode("/",$url)); $urlArray = array_reverse($urlArray); echo $urlArray[0]; 

    Thanks, but I’m looking for «index.html» or whatever the directory index file name is if you’re on «www.example.com», and can’t see if you’re on index.html, index.php, or some other index file.

    Unfortunately, the $_SERVER array entries may not always be available by your server. Some may be omitted, some not. With a little testing though, you can easily find out what your server will output for these entries. On my servers (usually Apache) I find that $_SERVER[‘DOCUMENT_ROOT’] usually gets me the base of the URI I’m after. This also works well for me in the production environment I work on (XAMPP). As my URI will have a localhost root. I have seen people encourage DOCUMENT_ROOT before in this situation. You can read all about the $_SERVER array here.

    In this example, I get the following results:

    echo $_SERVER['DOCUMENT_ROOT'] ; // outputs http://example.com 

    If you are working in a production environment this is very helpful because you won’t have to modify your URL’s when you go live:

    echo $_SERVER['DOCUMENT_ROOT'] ; // outputs C:/xampp/htdocs/example 

    ‘DOCUMENT_ROOT’ The document root directory under which the current script is executing, as defined in the server’s configuration file.

    Источник

Оцените статью