Reputation: 3442
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?
Upvotes: 3
Views: 2703
Reputation: 464
Try simply using a question mark:
<a href="?id=1">Link1</a>
<a href="?">Link without params</a>
Upvotes: 3
Reputation: 86
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?
Upvotes: 0