Answer the question
In order to leave comments, you need to log in
How to make a 301 redirect from uppercase to lowercase?
Hello. I made a redirect from uppercase to lowercase, everything worked, BUT the server response is still 200, how to make 301 ?
https://gyazo.com/fbe5ba20d5ae93fa72d398358ca198ae
I did everything by adding code to the index.php file
if ( $_SERVER['REQUEST_URI'] != strtolower( $_SERVER['REQUEST_URI']) ) {
header('Location: //'.$_SERVER['HTTP_HOST'] . strtolower($_SERVER['REQUEST_URI']), true, 301);
exit();
}
Answer the question
In order to leave comments, you need to log in
I hope it helps
function toLower() {
// Получаем запрашиваемый URL
$url = $_SERVER['REQUEST_URI'];
$params = $_SERVER['QUERY_STRING'];
// Если URL содержат имена файлов или имена файлов зависит от конкретики
if ( preg_match('/[\.]/', $url) ) {
return;
}
// Если URL содержит заглавную букву
if ( preg_match('/[A-Z]/', $url) ) {
// Преобразование URL в нижний регистр
$lc_url = empty($params)
? strtolower($url)
: strtolower(substr($url, 0, strrpos($url, '?'))).'?'.$params;
// если URL был изменен, перенаправлять
if ($lc_url !== $url) {
// 301 redirect на новый URL нижнего регистра
header('Location: '.$lc_url, TRUE, 301);
exit();
}
}
}
I never understood why this should be done
in linu case-sensitive file system, not in windows.
There is a non-zero chance to upload the Image.jpg file and not get a response on the server with this scenario.
Have you seen by the metric how many 404s are on your site due to case?
What is the purpose of this movement?
I hope it helps
I never understood why this should be done
in linu case-sensitive file system, not in windows.
There is a non-zero chance to upload the Image.jpg file and not get a response on the server with this scenario.
Have you seen by the metric how many 404s are on your site due to case?
What is the purpose of this movement?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question