Reputation: 4101
I am updating a website and having updated a directory name, I need to update all links for the old directory named blog
to the newly named press
I have tried this:
RewriteRule ^blog/(.*)$ /press/$1 [R=301,NC,L]
Which works perfect for any url's within that directory. i.e
website-url.com/blog/post-1
Goes too
website-url.com/press/post-1
However the blog index page still doesn't. I instead get a 404 when going to:
website-url.com/blog
If I have a trailing slash, it does work. Just not without. I know I can use an absolute path redirect like so:
Redirect 301 /blog http://www.website-url.com/press
But the domain could change so I want to keep the path relative / dynamic for this.
Upvotes: 1
Views: 13
Reputation: 784878
Have your rule like this:
RewriteRule ^blog(/.*)?$ /press$1 [R=301,NC,L]
This will match /blog
also as /.*
part is optional match.
Upvotes: 1