A
A
Alexey Chertok2018-04-18 19:37:08
PHP
Alexey Chertok, 2018-04-18 19:37:08

How to redirect from main to internal?

Good afternoon.
Please tell me how can I make a redirect from "/" to "/news" using PHP or NGINX, for example. At the same time, when visiting other pages, for example "/gallery", I would not be redirected to "/news".
Those. my main page is empty, I need it to be redirected to the module when visiting the main page.
How can this be implemented? Preferably with PHP.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2018-04-18
@Stalker_RED

php.net/manual/ru/function.header.php

$path = parse_url($url, PHP_URL_PATH);
if (empty( $path ))
    header('Location: http://www.example.com/news');

A
Argumentus, 2018-04-18
@Argumentus

Guys, it takes longer to ask such questions than to google.
header( 'Location: google.ru/search?q=redirect ' );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question