简体   繁体   English

.htaccess和wordpress网站-如何为不再有效的永久链接添加301重定向规则?

[英].htaccess & wordpress site - How to add 301 redirect rules for no longer valid permalink?

I recently did a big update on my wordpress site, thus some old permalink are invlid now. 我最近在我的wordpress网站上做了一个重大更新,因此现在已经包含了一些旧的永久链接。

Seach google for a tutorial on this and found a lot about static html page redirection examples or specific php page which are not what i'm looking for 向Google寻求有关此内容的教程,并发现了很多有关静态html页面重定向示例或特定php页面的内容,这些不是我想要的

Both my old and new permalinks are in path format, for example, i need redirect a couple urls of old gallery posts (deleted) which are 我的旧的和新的永久链接均采用路径格式,例如,我需要重定向几个旧画廊帖子(已删除)的网址,这些网址是

/2009/06/gallery/abc/
/2009/06/gallery/cba/
/2009/06/gallery/bbc/
/2009/06/gallery/aab/

to a new page which is 到新页面

/gallery/

How do i write a correct redirect rule for this? 如何为此编写正确的重定向规则?

Try something like this: 尝试这样的事情:

RewriteEngine On
RewriteRule ^/2009/06/gallery/\(?([^/]*)\/$ /gallery/ [R=301,L]
RewriteRule ^[0-9]{4}/[0-9]{2}/gallery/.*$ gallery [R=permanent,L]

Should get you to where you need to be. 应该让您到达需要的地方。 If you need the actual parameters (IE Date / Month / Title) passed along it is a bit of a change up, but do-able. 如果您需要传递实际的参数(IE日期/月/标题),则可以稍作修改,但是可以。

EDIT Fixed typo. 编辑固定错别字。

Personally, I would use the Redirection plugin rather than editing your .htaccess directly -- it's easier, less danger-prone, and will let you log what redirections have been happening. 就个人而言,我将使用重定向插件,而不是直接编辑.htaccess,它更容易,更不容易发生危险,并且可以让您记录发生了什么重定向。 It will also track 404 errors so you can see if you've forgotten to redirect anything. 它还会跟踪404错误,因此您可以查看是否忘记了重定向任何内容。

Then, if you're just redirecting a couple of fixed posts, it's just a matter of adding a simple rule for each redirect, with the old and the new URLs, on the Redirection configuration page. 然后,如果您仅重定向几个固定的帖子,则只需在“重定向”配置页面上为每个重定向添加一个简单的规则,并使用旧的和新的URL。 You can also use regular expressions, as with .htaccess, if you want to do anything more complicated. 如果您想做更复杂的事情,也可以使用正则表达式,例如.htaccess。

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

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