-2

My website configuration is :

L index.php
L assets
  L all my files like css/js...
L views
  L page1.php
  L page2.php

My index read the url, take the information after the "/", and he load the right view in "views". But when I'm calling another page, I'm using a <a href='page1.php'>

When I click on the link, my url is like : mydomain.com/page1.php, my website try to load the page1.php but it doesn't exist at the website racine. I want that my website load the index.php, in it, "page1.php" is watching then the right view can be loaded.

How can I do it without my 404 error...

Actually, when I'm clicking on a link, the index isn't called so all the time I have the 404 error.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Lucas
  • 26
  • 3
  • 4
    You will either need to link to a different target then - something like `index.php?page=page1` - or look into some basic _URL rewriting_. – CBroe Mar 29 '23 at 08:14
  • Sounds like maybe you need a routing engine. Or just simplify your design and put all the view files in the top-level folder – ADyson Mar 29 '23 at 08:15
  • I was thinking about it but don't want to use un get and I wanted to have my index as a "controller" – Lucas Mar 29 '23 at 08:22
  • If you don't use URL rewriting a file must exist in the exact location the URL specifies. htaccess is a common solution, for example download Drupal and look up how they do it. – Peter Krebs Mar 29 '23 at 08:55
  • I wanted to do it with the .htaccess but I don't know why, I got a lot of error I tried to modify the DirectoyIndex by my index but it doesn't work – Lucas Mar 29 '23 at 10:05
  • @Lucas maybe [Apache rewrite all paths to index.php](https://stackoverflow.com/questions/5965226/apache-rewrite-all-paths-to-index-php) or [Tips for debugging .htaccess rewrite rules](https://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite-rules) will help. – Zbigniew Mar 30 '23 at 21:50

1 Answers1

1

use the following code :

require_once('index.php');
Dipu
  • 11
  • 4
  • It's useless I don't want to import it in my file, I want that all my request are redirect in my index My index have a routing function to call the right view – Lucas Mar 29 '23 at 10:09
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 02 '23 at 18:27