Going to index.php without "index.php" with relative path

I have 2 pages at the same directory like the above.

At myPage.php I have the code below.

<a href="index.php">going to index</a>

If I click the link above, it will go to localDirectory/index.php.

Since “index.php” is a default page, It is possible, I think, to make it omit the default page name, i.e “index.php” in the code.

the code below are two of my trials for it.

trial code1

<a href="/">going to index</a>

The code above is not going to localDirectory/index.php, it goes to root/index.php.

trial code2

<a href="">going to index</a>

The code above is not going to localDirectory/index.php, it goes to localDirectory/myPage.php

trial code3

<a href="/localDirectory/">going to index</a>

The code above is possible to going index.php.
But I don’t like it because I should change the path when I move the project to another directory,

The / is what you should use as path to the root and let the default page open, often named index.html or index.php or other names in a priority order.

In your local setup, the root seems to be localDirectory but for the live site the host directory, where you place the whole site, is the root.

The site’s root directory in you dev machine is set in your virtual host configuration file and in the machines (OS) hosts file.

Maybe this thread here is of interest:

1 Like

You can define the default home/index page in htaccess.

DirectoryIndex index.php
3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.