Angel Aparicio
Angel Aparicio

Reputation: 374

Remove the filename of an url with htaccess

I had in my blog urls like these:

www.miblog.com/post-name/1.html
www.miblog.com/post-name-two/2.html
www.miblog.com/other-post/3.html

I have changed the permalinks to

www.miblog.com/post-name/
www.miblog.com/post-name-two/
www.miblog.com/other-post/

I want to put a 301 redirection from the olds url to the news url. Can I do this with htaccess?

The blog runs with Wordpress.

Thanks.

Upvotes: 1

Views: 62

Answers (1)

anubhava
anubhava

Reputation: 784878

Put this code on top of all other rules:

RewriteRule ^(.+?)/[^.]+\.html$ $1/ [L,NC,R=301]

Upvotes: 1

Related Questions