I
I
Issue2020-03-10 14:38:02
PHP
Issue, 2020-03-10 14:38:02

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


And in the sitemap.xml to indicate that the contact and catalog pages exist, can these pages be adequately indexed in searches?

I am interested in the shortest and simplest method of implementation, without complications and goodies. Please tell me how to implement this principle.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
CorteZzZz, 2020-03-10
@paulenot

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

F
FanatPHP, 2020-03-10
@FanatPHP

write in the address bar of your browser, PHP CNC

T
ThunderCat, 2020-03-10
@ThunderCat

mod_rewrite

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question