如何将所有帖子永久链接重定向到。html,在Wordpress中?现在我所有的帖子url都以结尾。html,但在此之前没有。html
更清楚地说,例如,类似于www.example的帖子url。com/postrl被重定向到www.example。com/姿势。html。一个接一个地重定向它们很简单,但我需要一个规则来重定向所有帖子。
非常感谢。
如何将所有帖子永久链接重定向到。html,在Wordpress中?现在我所有的帖子url都以结尾。html,但在此之前没有。html
更清楚地说,例如,类似于www.example的帖子url。com/postrl被重定向到www.example。com/姿势。html。一个接一个地重定向它们很简单,但我需要一个规则来重定向所有帖子。
非常感谢。
您可以编辑。直接使用htaccess或下载WordPress的htaccess编辑器插件。然后编写类似于以下内容的规则:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*) $1.html [nc]
更多信息detailed instructions您可以在Wordpress管理中为帖子永久链接添加扩展名,方法是Settings > Permalinks
以及使用创建自定义结构。最后是html。
例如:
(•) Custom Structure: /%category%/%postname%.html
不过,这只适用于帖子。如果要添加。html到页面的永久链接,您可以尝试以下插件Custom Page Extensions 或使用。位图发布的htaccess规则。这有风险。htaccess方法。他必须制定专门的规则,只针对帖子。并非服务器上的所有URL。
这是另一种方法。在Wordpress中工作,“有点”安全,但性能有点吃力,因为它需要在启动之前加载插件。理论很简单。重定向任何不包含的URL。在最后一段中,如/uri 或/uri/ 到/uri.html ... ONLY IF WordPress signals a is_404() error.
将此插件放在wp-content/mu-plugins/redirector中。php。
// Only here we have a valid is_404() to check if occurs.
add_action(\'wp\', function(){
if(!is_404()) return; // Bail if not a 404 (WordPress has got your back)
// Extract the URI and the Query-String (which is used later again)
list($uri, $qs) = explode(\'?\', $_SERVER[\'REQUEST_URI\']);
// Bail if current URL contains a . in the last segment of the URI
if(!preg_match(\'~/[^/\\.]+/?$~\', $uri)) return;
// Right-trim the last ./ and append the .html to it
$uri = rtrim($uri, \'/.\').".html".(!empty($qs) ? "?{$qs}" : null);
// Redirect to the new URL (with a 301 to keep link juice flowing) and hope it works :)
wp_redirect($uri, 301); die; // Over and out!
});
I\'d rather go for a .htaccess redirect anytime 但这要视情况而定。如果你真的通过改变permalink structure LIVE把你的博客弄得一团糟(这在实现某些流量/排名时是绝对不应该做的),这是一种更安全的方法,因为它只在is_404()发生。如果您在类别等方面有问题,请对其进行微调。Warning: PHP 5.3+使用的闭包。考虑恢复到PHP 5.2语法和兼容性。。。分配:)
您引用了您这样做是为了SEO目的。
目前没有任何证据表明这一点。URL末尾的html将改进Google的SEO,您也可以承认,Google正在为非html结尾的URL编制索引。
更重要的是。html扩展意味着内容是静态的,永远不会改变,这意味着谷歌可以索引它一次,永远不会返回。谷歌回来不是更好吗?尤其是考虑到一个页面的“新鲜度”现在在它的排名中起着重要作用。