Removing date from url using .htaccess

你离开我真会死。 提交于 2019-12-05 03:39:04

问题


I recently changed the permalink format of my blog so the date is removed:

http://site.com/blog/2011/01/post-name

is now

http://site.com/blog/post-name

The problem is the url with date is not redirected to new url. I tried some regular expressions in .htaccess but still get 404. Any ideas?


回答1:


The solution was

RedirectMatch 301 /blog/([0-9]+)/([0-9]+)/(.*)$ /blog/$3

http://www.catswhocode.com/blog/10-awesome-htaccess-hacks-for-wordpress




回答2:


Use this rewrite:

RewriteRule  blog/\d{4}/\d{2}/(.*) blog/$1 [R=301, L]

If your whole Wordpress installation is under the blog directory, and that's where the .htaccess file is located - use this:

RewriteRule  \d{4}/\d{2}/(.*) $1 [R=301, L]


来源:https://stackoverflow.com/questions/8796877/removing-date-from-url-using-htaccess

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