问题
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