Answer the question
In order to leave comments, you need to log in
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;
}
Answer the question
In order to leave comments, you need to log in
$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;
}
Take the $_GET array, turn it into a url and stick it on the right, no?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question