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.

16

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
3
  • 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 3: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 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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