B
B
Binarix2015-09-30 07:32:16
PHP
Binarix, 2015-09-30 07:32:16

How to put a condition on the page address?

Hello. There was such a task, you need to insert a condition in the page so that if it is domain.ru/news , then one script is executed, and if it is domain.ru/news/1 or domain.ru/news/vasia-pupkin , then another. This part after news/ can be anything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Zelensky, 2015-09-30
@SergeyZelensky-Rostov

You were prompted correctly but not quite, mod_rewrite is needed to make a single entry point to the application / site, and then you need a script (they call it a router), which will parse REQUEST_URI in parts and call a specific script according to the parsed, read about routing on php articles a bunch , and it's better to use MVC than to make a separate handler for each page

M
Maxim Smirnov, 2015-09-30
@MaxiStyle

Both answers are correct. This can also be done through mod_rewrite by creating an .htaccess file with the RewriteRule construct in the root of the site. So and means only PHP. The page address is in the global variable $_SERVER['REQUEST_URI']. And then it's a matter of technique: parse the variable and write the condition.
The second option will be easier for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question