I am trying to redirect all pages on my site in one directory to a specific page using htaccess.

Example anything like

  • example.com/forums/
  • example.com/forums/pages
  • example.com/forums/subdirectory/
  • example.com/forums/subdirectory/page.html

basically anything in /forums/ to only


It would be a permanent change. Basically, I bought a new domain from an auction that I migrated my site to and I am getting a lot of 404s from links to whoever was previously on this domain.

  • Does your new site have a folder 'forums' as well? That makes a big difference regarding the solutions. May 21, 2018 at 9:08

2 Answers 2


I bought a new domain from an auction that I migrated my site to and I am getting a lot of 404s from links to whoever was previously on this domain.

In this case, the 404 response is arguably the correct response. Correct for users and search engines. (You could even send a stronger / more deliberate "410 Gone" response - after all, these pages are not coming back it seems.)

A redirect only really makes sense if the content has moved to a different URL, or you have similar/related content at the new URL.

  • Redirecting users to a completely different page that is unrelated to the content they are expecting is confusing. And consequently, most users are likely to just "bounce". A better response would be a customised 404 that explains why the page no longer exists and tries to get the users attention in other ways, perhaps suggesting (some of your best) pages on your site that they may find interesting.

  • Redirecting search engine bots to a completely different/unrelated page is likely to be seen as a soft-404. But also, redirecting many URLs to a single page is very likely going to be seen as a soft-404.

So, you are not going to gain anything by redirecting in this instance and it could even be a step backwards.


If I'm not mistaking, it can be done quite easily like this:

RedirectMatch /forums/.* https://example.com/groups/subdirectory/

The dot means 'any character', an asterisk means 'times 0 or any greater number', and the referred-to location must always be written in full.

  • 2
    You probably mean RedirectMatch, instead of Redirect. RedirectMatch uses regex; Redirect uses simple prefix-matching. (However, you'd need to modify the pattern to include the start of string anchor and the trailing .* is superfluous. The target URL doesn't need to be "written in full", in that it doesn't need to be absolute. It can be a root-relative URL starting with a slash. Although an absolute URL is often recommended.)
    – MrWhite
    May 16, 2018 at 0:43
  • @MrWhite -- It indeed had to be RedirectMatch. But, depending on the server, Redirect uses more than just simple prefix-matching. Just test this .htaccess line on a site I created for yourself: Redirect http.*://gezondezorg.org/behandelkosten.*.php https://gezondezorg.org/vergoedingsregulering.php. (You'll have to believe me that this is the line.) May 16, 2018 at 18:53
  • "depending on the server" - in what way does it "depend on the server"? What is that directive supposed to do?
    – MrWhite
    May 18, 2018 at 9:52
  • @MrWhite ~ I did some tests yesterday that made me believe that the same type of regex redirect did work on one site at one host, and not on another site at another host. Checked and rechecked for syntax errors. But I cannot reproduce my findings today. I must have made a mistake. Sorry to waste your time. // Regarding the pattern modification, can you explain that with an example? Were you referring to the prefix matching or the matching in my answer? May 18, 2018 at 13:41
  • "I must have made a mistake." - You may have been seeing a cached response (a common problem when testing redirects)? The Redirect directive in your comment shouldn't have matched anything - hence my puzzlement. (But without knowing the actual URL that is being requested, it's difficult to test.) No worries, thanks for the follow-up. The Redirect directive does not support any kind of regex or wildcard syntax. So, characters like .* in the URL (first argument) will match a literal dot-asterisk.
    – MrWhite
    May 18, 2018 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.