Redirecting content of a folder to a new url with .htaccess

The structure of my site changed, so I have to redirect some of the urls.

I redirected some of the urls to the new url in the .htaccess file, that works fine:

Redirect 301 /folder/oldfolder1 https://www.domain.com/newfolder1/
Redirect 301 /folder/oldfolder2 https://www.domain.com/newfolder2/

I have one folder with several files, hundreds, that I need to redirect all to the same url.

I have tried several rewrite rules, but can’t get it work:
RewriteRule /folder/node https://www.domain.com/newfolder3/ [R=301]
or
RewriteRule /folder/node/(.*)$ https://www.domain.com/newfolder3/ [R=301]

The urls that I want to redirect are for example:
https://www.domain.com/folder/node/4643
https://www.domain.com/folder/node/40
https://www.domain.com/folder/node/4243

They should all be sent to https://www.domain.com/newfolder3/

I would appreciate some input, Thanks!

https://httpd.apache.org/docs/2.4/mod/mod_alias.html#RedirectMatch is probably easier :slight_smile:

Thanks rpkamp!

This worked:

RedirectMatch 301 ^/folder/node/.*$ https://www.domain.com/newfolder3
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.