开发者

.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.

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

Both my old开发者_Python百科 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?


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.

EDIT Fixed typo.


Try something like this:

RewriteEngine On
RewriteRule ^/2009/06/gallery/\(?([^/]*)\/$ /gallery/ [R=301,L]


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. It will also track 404 errors so you can see if you've forgotten to redirect anything.

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. You can also use regular expressions, as with .htaccess, if you want to do anything more complicated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜