Redirect all posts on wordpress

半城伤御伤魂 提交于 2019-12-13 06:55:13

问题


I moved my site to a new host but by accident permalink was changed. First i had a /%postname%.html and after moving to new host it got changed to /%postname%/ . I fixed the permalink and is working fine except when Google crawls my website google search results return 404 error pages.

I tried every redirect plugin and nothing is working. I want to redirect every post that is http://www.website.com/sample-post/ to http://www.website.com/sample-post.html

I can not add every single post because there are around 100k posts.

Any ideas? thanks


回答1:


Firstly you are attempting to treat the symptom, not the problem. This will cause more issues for you in the future.

However, the best way to do what you want is to use rewrite rules in apache's .htaccess file.

Something like this should work. Modify as desired.

# add .html file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+)$ /$1.html [L]


来源:https://stackoverflow.com/questions/27429088/redirect-all-posts-on-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!