I have problems with the redirection of my old website to our new website under a new domain. The old website was created with Wordpress and the simple redirect 301 was successful. However, some pages have this structure:

  • old.example/hotel/
  • old.example/hotel/suites/
  • old.example/hotel/rooms/
  • old.example/hotel/studio-apartments/

I had problems redirecting this to the new website because the simple redirect 301 only worked for the /hotel redirection.

I have also tried this:

RedirectMatch 301 /hotel/(.*) https://new.example/accommodation/

But this redirects all pages to the same new one. I would like to accomplish this:

  • old.example/hotel/ to https://new.example/accommodation/
  • old.example/hotel/suites/ to https://new.example/suites/
  • old.example/hotel/rooms/ to https://new.example/rooms/
  • old.example/hotel/studio-apartments/ to https://new.example/studio-apartments/

I would really appreciate any help!

  • Sorry but this question has been asked before in various forms already on Pro Webmasters. The one linked has the most common redirects for Apache, you should find what you are looking for at the bottom. Commented Nov 28, 2018 at 17:49
  • Also see: serverfault.com/questions/214512/… Commented Nov 28, 2018 at 17:54

1 Answer 1


You have two different (types of) redirects here, so you'll next at least two "redirect" directives. You can still use the simple Redirect directive for one of them.

For example, the more specific redirect should be first:

# Redirect /hotel/ to https://new.example/accommodation/
RedirectMatch 302 ^/hotel/?$ https://new.example/accommodation/

# Redirect /hotel/<anything> to https://new.example/<anything>
Redirect 302 /hotel/ https://new.example/

This redirects /hotel/ (or /hotel - trailing slash omitted) to /accommodation/ at the new site.

The "simple" Redirect directive is prefix-matching, and everything after the match is copied to the end of the target URL. So, everything after /hotel/ is redirected to the document root of the new site. eg. /hotel/foo is redirected to https://new.example/foo.

However, if you specifically only want to target /suites/, /rooms/ and /studio-apartments/ then you should change the Redirect directive to RedirectMatch also:

# Redirect /hotel/<specific> to https://new.example/<specific>
RedirectMatch 302 ^/hotel/(suites|rooms|studio-apartments)/?$ https://new.example/$1/

This now only targets those specific 3 URLs as mentioned.

These directives do assume a couple of things:

  1. The old and new domains point to different filesystems. (In order to avoid a potential redirect loop.) Although with these specific URLs you will be OK either way.

  2. The old site is no longer active and you have removed the existing mod_rewrite directives (WordPress front-controller) from .htaccess. Although, again, it may still "work" with the old directives in place, but they are being unnecessarily processed.