How to change the default index page in .htaccess

Many times you may need to use a different file name for the default index page. Most web servers use a list of default index pages, like index.html, index.htm, index.php, index.phtml etc.

You can easily instruct the webserver to load a specific file via the .htaccess file. Just edit the .htaccess file and add the lines:

RewriteEngine on
DirectoryIndex newindex.html

Now, instead of the default index.html, index.php file, the server will load the newindex.html file. To have a list of possible index filenames, use:

RewriteEngine on
DirectoryIndex newindex.html newindex.php newindex2.php

Note that the above syntax is equivalent with:

RewriteEngine on
DirectoryIndex newindex.html
DirectoryIndex newindex.php
DirectoryIndex newindex2.php

The Apache server will serve the first existing file from the list. It will try to load newindex.html. In case it doesn’t find it will look for the next file – newindex.php – and so on.

If none of the resources exist and the Indexes option is set, the server will generate its own listing of the directory.

DirectoryIndex Directive

Notice that the .htaccess file is a hidden file. If you can’t see it in your file manager then you must enable listing of hidden files.
Show Hidden Files in FileZilla
Show Hidden Files in cPanel

DirectoryIndex Directive

Redirect all URLs to another domain with .htaccess

You changed your domain name and you want to redirect all requests to the new domain? You can create such a redirect by adding a few lines in the site’s .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$ "$1" [R=301,L]

To redirect with a 301 HTTP response ( Moved Permanently ), use R=[301,L] on the last line.

To redirect with a 302 HTTP response ( Moved Temporarily ), use R=[302,L] on the last line.

The L indicates that this is the last rule from the .htaccess file that will be processed.

301 Moved Permanently
The requested resource has been assigned a new permanent URL and
any future references to this resource should be done using that

RFC 1945

302 Moved Temporarily
The requested resource resides temporarily under a different URL.

RFC 1945

RFC 1945

Connect to a non-default SFTP port

SFTP, the abbreviation for SSH (or Secure) File Transfer Protocol is using by default port 22. Many servers nowadays are using different port numbers, like 2222. We will show in this article how to connect to an explicit port number, using the sftp utility.

The sftp command information:

root@web [~]# sftp
usage: sftp [-1246aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
          [-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit]
          [-o ssh_option] [-P port] [-R num_requests] [-S program]
          [-s subsystem | sftp_server] host
       sftp [user@]host[:file ...]
       sftp [user@]host[:dir[/]]
       sftp -b batchfile [user@]host

To connect with sftp to a specific port as root, use sftp -P port_number hostname

root@web [~]# sftp -P 2222
The authenticity of host '[]:2222 ([]:2200)' can'                                                                                        t be established.
ECDSA key fingerprint is SHA256:MqoUe1cJlbAqFidXZbV4cSMWfi1meCQ6ZtMiIzZ7yQE.
ECDSA key fingerprint is MD5:06:95:95:63:2f:ea:7a:4c:e7:36:62:73:f6:83:d2:04.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '[]:2222' (ECDSA) to the list of known hosts.'s password:
Connected to
sftp> cd /
sftp> bye
root@web [~]#

To connect with a username, use sftp -P port_number user@hostname

How to create phpinfo pages

Do you want to know PHP/Apache information? The easiest way is to use the phpinfo() function.

1. Log in to your control panel (cPanel, DirectAdmin, CWP etc)

2. Go to the File Manager and create a new file – phpinfo.php – in your public directory (where your site’s files are)

3. Edit this file and put the text:


4. Access the newly created file –

phpinfo() output

If you are an admin you can easily create such a file for the specific user:
1. navigate to the specific directory:

cd /home/username/public_html/

2. create a phpinfo file, edit it with the vi/nano editor and add the above PHP code:

touch phpinfo.php
nano phpinfo.php

3. modify phpinfo.php file permissions:

chmod 644 phpinfo.php
chown <username>:<username> phpinfo.php

4. access the file phpinfo.php in your web browser or send the link to the client.

Notice that on some servers the phpinfo() function is disabled. In this case, you may need to use other functions like ini_get(). A simple PHP file to get the most common PHP values is here

phpinfo() help

How to list all logged-in users

To see the connected users on your server, you can use the shell commands: w, who or users. You can use the three commands without any parameters. For more options run the commands with the –help argument.

In the examples below, you can see there are three logged in users – you can see their IPs, logged-in time etc.

The w shell command:

root@s04 [~]# w
 01:42:08 up 22 days, 23:37,  3 users,  load average: 0.43, 0.58, 0.66
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0     01:40    1:12   0.04s  0.04s -bash
tony     pts/1     01:41    8.00s  0.03s  0.03s -bash
adam     pts/2     01:48    0.00s  0.03s  0.00s w

As you can see, the header os the result will show the current time of the server, the uptime, how many users are connected and the server load for the last 1, 5 and 15 minutes.

The next lines will show for each user – the login name, tty name, the Ip of their host, login time, idle time, JCPU, PCPU, and the current command line.

The who shell command:

root@s04 [~]# who
root     pts/0        Jan 19 01:40 (
tony     pts/1        Jan 19 01:41 (
adam     pts/2        Jan 19 01:48 (

The who command is very similar to w.

The users shell command:

root@s04 [~]# users
root tony adam

This command will only list the usernames.

w man page
who man page

Page 2 of 10
1 2 3 4 10