Поправить 301 редирект для WordPress сайта
В functions.php темы WordPress добавлен код, который добавляет к адресу блог-поста "/blog/". При этом в htaccess сайта добавлено правило для перенаправления всех возможных запросов на non-www+htpps версию через 301 редирект.
Проблема в том, что сейчас сайт отдает ответ 200 на любые страницы, связанные с /blog/. Надо исправить ситуацию - чтобы все блог-посты во всех возможных вариациях отдавили 301 с перенаправлением на non-www+htpps.
Адрес сайт предоставлю исполнителю.
htaccess:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{ENV:HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
functions.php:
// Function to add blog prefix in URL
/**
* Add new rewrite rule
*/
function create_new_url_querystring() {
add_rewrite_rule(
'blog/([^/]*),
'index.php?name=$matches[1]',
'top'
);
add_rewrite_tag('%blog%','([^/]*)');
}
add_action('init', 'create_new_url_querystring', 999 );
/**
* Modify post link
* This will print /blog/post-name instead of /post-name
*/
function append_query_string( $url, $post, $leavename ) {
if ( $post->post_type == 'post' ) {
$url = home_url( user_trailingslashit( "blog/$post->post_name" ) );
}
return $url;
}
add_filter( 'post_link', 'append_query_string', 10, 3 );