M
M
Matvey Mamonov2015-04-02 21:37:42
PHP
Matvey Mamonov, 2015-04-02 21:37:42

How to organize a jump from any address to a single request handler file?

I looked through the WordPress structure and found out that the page.php file handles all the pages in this CMS. I want to implement something similar (or not, because I don’t know exactly how it works there).
In short, is it even possible to implement such a thing?
When you enter any link to any page of my site (even non-existent), for example,
my.site/eijweoungerkg
or when you follow a link to this page using htaccess, you are redirected to this very page.php, which looks at what is after the slash, and if the page with If there is such an address in the database, then it loads it, and if not, then a 404 redirect occurs?
And if it is possible, then how to transfer to page.php the very link that the user is trying to go to?
And in general, how competent is such an approach, maybe I just came up with an irrational method?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
FanatPHP, 2015-04-02
@eucalipt

for apache webserver

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ page.php

Z
zenaku, 2015-04-02
@zenaku

This is already the beginning of the mvc implementation .
Here, read on Habré how to implement all this. Link 1 and link 2 and many of them
Issuing a page from the database is not the best option.
Learn php frameworks, it will make it easier for you to develop and understand mvc, and also teach you many new features.

S
Sergey Kordubin, 2018-12-20
@Roon_Boh

1. RewriteEngine On
2. RewriteCond %{REQUEST_FILENAME} -s [OR]
3. RewriteCond %{REQUEST_FILENAME} -l [OR]
4. RewriteCond %{REQUEST_FILENAME} -d
5. RewriteRule ^.*$ - [L]
6. RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
7. RewriteRule ^(.*) - [E=BASE:%1]
8. RewriteRule ^(.*)$ %{ENV:BASE}/page.php [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question