V
V
Vitaly2019-02-10 14:59:31
PHP
Vitaly, 2019-02-10 14:59:31

How to make a CNC like mysite.ru/product/Item1?

Hello!
There is a website in PHP with a product catalog.
I want to make the product card open at mysite.ru/product/Item1
There is a /product/ directory, it contains an index.php file - which should get the name of the product (Item1) and display the corresponding product card by this name.
Question: how to make it so that when you go to this address, not a message about the missing page is displayed, but index.php is launched? And how to get the name of the product (Item1) in it?
I suppose that it is necessary to make redirects in .htaccess, but how then to get Item1 ?
UPD: Is it possible to make a redirect in htaccess to index.php which is not at the root, but a level higher? Those. from the example above in mysite.ru/product/index.php
If you use the option that the redirect goes to 1 specific file, and this file will already include other scripts depending on the query string - how correct and beautiful is this? And what difficulties can arise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Popov, 2019-02-10
@xSnaip

I recommend to look at any modern framework - Laravel / (God forgive me) Yii2 / Slim / (take any). And see how the entry point is made there. In short, the FrontController pattern
is used . The public directory is created and accessed by the server. Further, depending on the server you are using, the corresponding commands are written for the server.
.htacces кладется в директорию public

Options +FollowSymLinks -Indexes
RewriteEngine On

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

В конфигурационный файл сервера прописывается что-то подобное.
location / {
try_files $uri $uri/ /index.php?$query_string;
}
</spoiler>
</spoiler>

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question