3

I have a page name index.php. It is in the folder name test. So if I call localhost/test I can see the page.

I have links in the page that pass parameters:

<a href="?id=1">Link1</a>
<a href="?id=2">Link2</a>

So the URL is localhost/test/?id=1

After that I want to link to the root page (index.php) but I don't want to use href="index.php". I want a link for root page without parameters. So when the user click the link, he/she can go to localhost/test again.

Is there any standard or something?

Vahid
  • 3,384
  • 2
  • 35
  • 69

3 Answers3

3

Try simply using a question mark:

<a href="?id=1">Link1</a>
<a href="?">Link without params</a>
Jay Goettelmann
  • 375
  • 1
  • 6
  • 15
0

I allways solved this with PHP. In PHP I would have a string variable named '$APP_ROOT' and assign the path to index.php to it. Then you can use this variable to print/echo it in the HTML.

Example (not sure if syntaxt is ok):

<?php
$APP_ROOT = 'localhost/test';
?>

<a href="<?php echo $APP_ROOT . '?id=1'; ?>">Link1</a>
<a href="<?php echo $APP_ROOT . '?id=2'; ?>">Link2</a>

With a template engine this could be cleaner. The $APP_ROOT variable needs to be changed when you deploy it to the server.

BUT maybe even more easy is the HTML base tag. I dont know for sure if the base tag is good, I have never used it. Large amount of information is here: Is it recommended to use the <base> html tag?

Community
  • 1
  • 1
user2140283
  • 86
  • 1
  • 7
  • Thanks for the solution but I need the HTML one. The "../test" solved the problem. Thank you. – Vahid Oct 08 '14 at 09:15
0

The "../test" solved my problem.

Vahid
  • 3,384
  • 2
  • 35
  • 69