我之前用 WordPress 制作了我的網站。我有一些似乎做得很好的帖子(SEO)。我的帖子的網址是www.sitename.com/this-is-post-title。我已經用 html 重建了站點,并計劃將博客文章移動到 blog.sitename.com,以便新的 url 將是 blog.sitename.com/this-is-post-title。
我創建了一個 html 檔案作為 this-is-post-title.html 并將重定向設定為 blog.sitename.com/this-is-post-title。這是重定向代碼
<meta http-equiv = "refresh" content = "0; url = https://blog.sitename.com/this-is-post-title/" />
它在訪問 sitename.com/this-is-post-title.html 時作業正常,但在訪問 sitename.com/this-is-post-title 時卻不行。我以前的帖子也沒有 .html,因為我在 WordPress 中作業。對我有什么幫助嗎?
uj5u.com熱心網友回復:
您可以在.htaccess檔案中添加這一行:
Options Multiviews
Multiviews是 Apache 中的一項功能,它將通過搜索具有擴展名的類似名稱的檔案來提供來自沒有擴展名的 URL 的內容。
或者,您可以在.htaccess
RedirectMatch permanent ^/this-is-post-title$ /this-is-post-title.html
或者
RewriteEngine on
RewriteRule ^/this-is-post-title$ /this-is-post-title.html [R=301,L]
uj5u.com熱心網友回復:
如果它是一個 wordpress 網站,您可以使用這段代碼重定向到另一個頁面。將其粘貼到functions.php下
function redirect_page() {
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
$currenturl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$currenturl_relative = wp_make_link_relative($currenturl);
switch ($currenturl_relative) {
case '[from slug]':
$urlto = home_url('[to slug]');
break;
default:
return;
}
if ($currenturl != $urlto)
exit( wp_redirect( $urlto ) );
}
add_action( 'template_redirect', 'redirect_page' );
使用您的網址更改 [from slug] 和 [to slug]
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/479841.html
