donglin1692 2016-12-17 16:40
浏览 40

.htaccess redirect for wordpress永久链接,不包括uploads文件夹

I have changed the permalink structure for a wordpress site from

Day and name    http://www.domain.com/2016/12/17/sample-post/

to

Post name   http://www.domain.com/sample-post/

using the following htaccess rewrites, which do work:

RedirectMatch 301 ^/[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}/(.*)$ http://www.domain.com/$1
RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/(.*)$ http://www.domain.com/$1
RedirectMatch 301 ^/(.*)/[0-9]{4}/[0-9]{2}/(.*)$ http://www.domain.com/$1/$2

however the problem now, is that its rewriting image URLs as well, example:

http://www.domain.com/wp-content/uploads/2016/12/Lego-2.jpg

is now redirecting to

http://www.domain.com/wp-content/uploads/Lego-2.jpg

which is breaking images. How can I exclude wp-content/uploads from the RedirectMatch htaccess rules.

  • 写回答

1条回答 默认 最新

  • dongtai6741 2016-12-17 17:15
    关注

    You should be able to make that change in settings > permalinks without writing your own htaccess provide htaccess is writable just add /%postname% to the end of custom in permalinks setting and it will not break image or style links

    评论

报告相同问题?