E
E
Edward2017-03-13 01:16:17
PHP
Edward, 2017-03-13 01:16:17

How to dynamically create a page in PHP depending on the url?

Hello everybody!
How to make it so that when requesting different urls, php gives a page made through one php file, something like this.

<?php 
     include 'header.php';
     include 'sitebar.php';
     include 'page_content'.url.'.php';
     include 'footer.php';
 ?>

Do I need to write something in .htaccess or what?
And for example, so that requests for example.com/front-page1, example.com/front-page2 and example.com/front-page3 are processed by one php file (for example, example.com/front-pages.php), and requests for example. com/user-page1, example.com/user-page2 and example.com/user-page3 processed one php file (for example example.com/user-pages.php).
PS. I can’t even form a request in Google, it doesn’t give out everything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Sisyukin, 2017-03-13
@ed_milson

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

Since there is only one entry point to the application, create your own class (function) of the route and parse the requests that come in and give out what you want.
This is for learning and understanding how what works, but it’s better to use ready-made solutions, for example, like FastRout

A
Archakov Dennis, 2017-03-13
@archakov06

Yuzai Laravel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question