P
P
Pavel Inky2014-11-27 12:48:17
PHP
Pavel Inky, 2014-11-27 12:48:17

How to make a 301 redirect with GET?

Hi all.
Please tell me, I
ran into a problem with setting up the CNC and 301 redirect
The site has pages:
site.com/region/section/13 - this is a catalog with products, there is also pagination with pages - site.com/region/section/13?page =2...
I need to make a CNC and a Redirect of the form:
from site.com/region/section/13 to site.com/region/section/kuhonnaja-mebel , But if GET appears, then this is also:
site.com/region /section/13?page=1 to site.com/region/section/kuhonnaja-mebel?page=1 .
How can this be implemented?
tried via:

$sru = strtolower($_SERVER['REQUEST_URI']);
$url_array = array(
  '/region/section/13' => '/region/section/kuhonnaja-mebel',
);
if(isset($url_array[$sru])){
  header('HTTP/1.1 301 Moved Permanently');
  header('Location: http://'.$_SERVER['HTTP_HOST'].$url_array[$sru]);
  exit;
}

redirects only from site.com/region/section/13 to site.com/region/section/kuhonnaja-mebel... How should GET be taken into account?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evervess, 2014-11-27
@inkyrein

$raw_uri = $_SERVER['REQUEST_URI'];
$uri_map = array(
    '/region/section/13' => '/region/section/kuhonnaja-mebel',
);
if (count($_GET)) {
    $tmp_uri = explode('?', $raw_uri);
    $uri['address'] = strtolower($tmp_uri[0]);
    $uri['request'] = '?' . $tmp_uri[1];
} else {
    $uri['address'] = strtolower($raw_uri);
    $uri['request'] = '';
}
if (isset($uri_map[$uri['address']])) {
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $uri_map[$uri['address']] . $uri['request']);
    exit;
}

This is how it should work, haven't tested it.

I
Ilya Plotnikov, 2014-11-27
@ilyaplot

Take the $_GET array, turn it into a url and stick it on the right, no?

F
FanatPHP, 2014-11-27
@FanatPHP

You just need to think.
Take and mentally imagine how site.com/region/section/13?page=1 differs
from
site.com/region/section/13
And
then think about how to get the second from the first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question