.htaccess URL 重写 WordPress 旧固定链接

发布于 2024-12-29 08:20:12 字数 286 浏览 0 评论 0原文

我有一个博客,其中有基于旧日期的永久链接。 EG:Blog.com/2011/10/post-name

我的新永久链接现在是基于类别和帖子名称的,但前面也有 /blog/。 EG:Blog.com/blog/category-name/post-name

我需要在 HT Access 文件中做什么来克服问题?到目前为止我有类似的东西但目前没有工作..

#RewriteRule ^[0-9]{4}/[0-9]{2}/.*$ /blog/$1 [R=permanent,L]

I have a blog which had old date based permalinks. EG: Blog.com/2011/10/post-name

My new permalinks now are category and post name based, but also are preceded by /blog/. EG: Blog.com/blog/category-name/post-name

What do i need to do in my HT Access file to overcome thins? I have something like this so far but currently not working..

#RewriteRule ^[0-9]{4}/[0-9]{2}/.*$ /blog/$1 [R=permanent,L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

数理化全能战士 2025-01-05 08:20:12

如果 /blog/2011/10/post-name 也已重定向您 /blog/category/post-name (确保它是 301),那么您所需要的一切要做的就是发送
/2011/10/post-name/blog/2011/10/post-name

您可以通过将以下规则放入根目录的 .htaccess 文件中来完成此操作您网站的。

RewriteEngine on
RewriteBase /

#redirect blogs posts to /blog
RewriteRule ^([0-9]{4}/[0-9]{2}/.+)$ /blog/$1 [R=301,L]

If /blog/2011/10/post-name already redirects you too /blog/category/post-name (make sure it is a 301), then all you need to do is to send
/2011/10/post-name to /blog/2011/10/post-name

You can do this by putting the rules below in the .htaccess file in the root of your site.

RewriteEngine on
RewriteBase /

#redirect blogs posts to /blog
RewriteRule ^([0-9]{4}/[0-9]{2}/.+)$ /blog/$1 [R=301,L]
月下伊人醉 2025-01-05 08:20:12

这看起来与将网站从 /blog/ 移动到根目录有关;是这样吗?

如果是这样,您应该在数据库中查找/替换 URL,以便不必使用 .htaccess 规则。

在 phpmyadmin 中运行的此查询将更新帖子 guid 以摆脱 /blog/ 路径:

UPDATE wp_posts SET guid = replace(guid, 'http://www.domain.com/blog/','http://www.domain.com/');

您可能还需要更改帖子内容中的 URL:

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.domain.com/blog/', 'http://www.domain.com/');

This looks like it has to do with moving the site from /blog/ to root; is that the case?

If so, you should find/replace the URLs in the database as to not have to use a .htaccess rule.

This query run in phpmyadmin will update post guid's to get rid of the /blog/ path:

UPDATE wp_posts SET guid = replace(guid, 'http://www.domain.com/blog/','http://www.domain.com/');

You may also need to change URLs in post content:

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.domain.com/blog/', 'http://www.domain.com/');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文