简体   繁体   English

.htaccess URL重新写入Wordpress旧的永久链接

[英].htaccess URL ReWrite Wordpress Old Permalinks

I have a blog which had old date based permalinks. 我有一个博客,其中有基于旧日期的永久链接。 EG: Blog.com/2011/10/post-name EG:Blog.com/2011/10/post-name

My new permalinks now are category and post name based, but also are preceded by /blog/. 我的新永久链接现在基于类别和帖子名称,但也以/ blog /开头。 EG: Blog.com/blog/category-name/post-name EG:Blog.com/blog/category-name/post-name

What do i need to do in my HT Access file to overcome thins? 我需要在HT Access文件中做什么来克服瘦身? I have something like this so far but currently not working.. 到目前为止,我有类似的内容,但目前无法正常工作。

#RewriteRule ^[0-9]{4}/[0-9]{2}/.*$ /blog/$1 [R=permanent,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 如果/blog/2011/10/post-name已经将您重定向到/blog/category/post-name (确保它是301),那么您要做的就是将/2011/10/post-name发送到/blog/2011/10/post-name

You can do this by putting the rules below in the .htaccess file in the root of your site. 您可以通过将以下规则放在网站根目录下的.htaccess文件中来实现。

RewriteEngine on
RewriteBase /

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

This looks like it has to do with moving the site from /blog/ to root; 这似乎与将站点从/ blog /移至根目录有关。 is that the case? 是这样吗?

If so, you should find/replace the URLs in the database as to not have to use a .htaccess rule. 如果是这样,您应该查找/替换数据库中的URL,而不必使用.htaccess规则。

This query run in phpmyadmin will update post guid's to get rid of the /blog/ path: 在phpmyadmin中运行的此查询将更新post guid来摆脱/ blog /路径:

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: 您可能还需要更改帖子内容中的URL:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM