9

I have this in my httpd.conf file:

<VirtualHost IP.AD.DR.ESS:80>
    ServerName example.com
    Redirect Permanent / https://example.net/
</VirtualHost>

This is successfully redirecting everything formerly at http://example.com to its new corresponding location at https://example.net. However, I've discovered one directory, example.com/specialdir/, has to stay on the old server since the data it needs to access isn't on the new server. (It's going to take months to finish the migration involving a couple dozen other sites.)

Is there a reasonable way to fix this in httpd.conf or am I going to have to use a bunch of .htaccess files? I suspect there's something I can do with <Location> containers, but I don't know the right question to ask to find the information.

FKEinternet
  • 291
  • 2
  • 4
  • 11

1 Answers1

18

You can modify the Redirect directive to instead make use of a RedirectMatch and use a pattern excluding /specialdir:

RedirectMatch Permanent "^(/(?!specialdir/).*)" https://example.net/$1
hjpotter92
  • 670
  • 1
  • 10
  • 20
  • 1
    You saved me from pulling out the rest of my hair ;) – FKEinternet Jul 22 '17 at 11:06
  • 5
    It works, but it was adding a double slash for some reason, so had to do it like: `https://example.net$1` – justabit Apr 22 '18 at 03:37
  • 1
    I was getting double slashes as well. Plus had to exclude two folders, so I did this: `RedirectMatch permanent "^(/(?!(files1/|files2/)).*)" https://www.example.com$1` Likewise word `permanent` can be replaced by `301` which is same, or with `302` which means temporary redirect. Thanks for the answer! – LuxZg Nov 25 '20 at 09:15