So far, I've been using GET parameters to route between the pages of my website (hosted on the server of my university). I'd like to make use of $_SERVER["PATH_INFO"]
instead as it's, I guess, a cleaner way to route between pages.
I'd like to go from:
www.universitydomain.subdomain/myProject/index.php?action=imageGallery
To:
www.universitydomain.subdomain/myProject/index.php/imageGallery
I have 3 pages:
- My main page, index.php
- My image gallery page, currently accessible
when the GET parameter
action
equals "imageGallery" - A page to add an image to my gallery, accessible when the GET parameter
action
equals "addImage"
On each of this page is a menu composed a <a>
links:
<a href="index.php" > Main page </a>
<a href="?action=imageGallery" > Gallery </a>
<a href="?action=addImage" > Add image </a>
When doing it this way, everything works fine. So I tried to use a PATH_INFO
style URL like so:
<a href="index.php" > Main page </a>
<a href="index.php/imageGallery" > Gallery </a>
<a href="index.php/addImage" > Add image </a>
If I'm on the gallery page, I expect the <a>Main pagey</a>
link to write index.php
in my URL, which would bring me back to the main page. Yet, this happens :
- I'm on
index.php
. The URL iswww.universitydomain.subdomain/myProject/index.php
- I click the second link to get to the gallery. The URL becomes
www.universitydomain.subdomain/myProject/index.php/imageGallery
- I click the first link to get back to the main page. The URL becomes
www.universitydomain.subdomain/myProject/index.php/index.php
- On the third step, If instead of getting back to the main page, I
click on the third link to get to the
addImage
page, the URL becomeswww.universitydomain.subdomain/myProject/index.php/index.php/addImage
Why is that ? I haven't been able to reproduce a minimal example of my issue so it seems to be tied to my project (which is a little bit too large to include in this post unfortunately). Even without being able to reproduce this issue, some of you may relate to it and have something to propose.
I have the impression that, after getting to the gallery page (which has the URL /myProject/index.php/imageGallery
), the "reference path" of my page has changed to /myProject/index.php/
from /myProject/
and thus, when clicking on the <a href="index.php">
link, it redirects me to /myProject/index.php/index.php
instead of /myProject/index.php/