Answer the question
In order to leave comments, you need to log in
What are the site navigation methods, with one index.php?
I want to make a light website and try to implement navigation. In theory, a person entering the site launches index.php which determines the url. If, for example, /catalog/ comes after the domain, then display $catalog.
The question is, at first I thought that I needed a 404 redirect, but then I wondered where to get that very url/catalog from if the redirect reloads the page. I heard about shamanism with .htaccess, but I don't know how it works. The same question arose about SEO optimization.
If the condition is written in index.php:
if $path = 'catalog/'
- - - echo $catalog;
elif $path = 'contact/'
- - - echo $contact;
else:
- - - echo $page_not_found
Answer the question
In order to leave comments, you need to log in
Google "PHP Router". There will be both about CNC and about mod_rewrite.
In a nutshell, you need to redirect all requests to index.php - this is done through htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
Next, in index.php, get, for example, $_SERVER['REQUEST_URI'], parse it, for example, parse_url, and then, depending on the result
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question