Simon Suh Simon Suh - 4 months ago 9
PHP Question

How do I test php pages on XAMPP without typing "localhost/mysites/practice.php" and just clicking on php/html icon?

How do I do this? It's not much of a hassle but at times it would be quite convenient if I could just double click on the php/html file to test my php scrips on my localhost/XAMPP server instead of the the double-click directing to me the location on the hard disk where the php server is not being used.

To clarify, I meant being able to skip typing the "localhost/" part of the file address in the browser address bar every time I want to test a php script.

Answer

Edit your hosts file and change localhost to "1" or as you like you will be able to access root directory files as 1/file.php.Do the following steps

My Computer > C: (or whatever drive Windows is on) > WINDOWS > system32 > drivers > etc > hosts

Note: If you aren't sure where My Computer is or you just want to use a keyboard shortcut to open it, you can hold down the Windows key on your keyboard while you press the ā€œEā€ key.

Right-click on the HOSTS file, and click Open. A window will appear asking what to open it with; find Notepad, select it, and click OK.

If you've never edited your HOSTS file before, this is what it should look like:

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost

change localhost to 1

you will be able to access the file using http://1/file.php