Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing date from url using .htaccess

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?

like image 315
goksel Avatar asked Dec 07 '22 17:12

goksel


2 Answers

The solution was

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

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

like image 65
goksel Avatar answered Jan 11 '23 17:01

goksel


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]
like image 36
Joseph Silber Avatar answered Jan 11 '23 18:01

Joseph Silber