Wordpress missing blog permalink

倖福魔咒の 提交于 2019-12-20 04:37:21

问题


I set up my Wordpress website, imported all blog post and submitted my sitemap to Google last month.

I realized that my blog posts appear like: www.domain.com/blog-post-name <- without the /blog/ directory. I can add the blog directory by changing the Wordpress permalinks, but then when someone goes to the old blog URL, they get a 404 error.

Is it possible to direct users who go to www.domain.com/blog-post-name to www.domain.com/blog/blog-post-name

Thanks


回答1:


This should work for you (changing the www.domain.com to your domain) :

Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/blog/

# Don't apply to URLs that go to existing files or folders
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /blog
RewriteRule ^(.*)$ http://www.domain.com/blog/$1 [L,R=301]

EDIT: This will rewrite specific urls:

RewriteEngine On
RewriteRule ^blog-post1$ http://www.example.com/blog/blog-post1 [R=301,L]
RewriteRule ^blog-post2$ http://www.example.com/blog/blog-post2 [R=301,L]


来源:https://stackoverflow.com/questions/21997835/wordpress-missing-blog-permalink

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