2

I'm currently redirecting all requests to my Apache server from olddomain.com to newdomain.com -- it works fine but I actually need just ONE file to still be loaded as if it's at olddomain.com.

Here's what the important bit looks like now:

<VirtualHost *:80>
ServerName olddomain.com
ServerAlias olddomain.com

Redirect / http://newdomain.com/
</VirtualHost>

I loved this simple Redirect / http://newdomain.com solution because it does exactly what I want and is so simple even I can understand it! BUT how do I make an exception so that when someone/something goes to http://olddomain.com/excludedfile.php, it loads to the expected domain name? The solutions I've found so far seem to be for mod_rewrite setups. If mod_rewrite is what's required I guess I can live with it but I'd rather not...

Why I need this: I just submitted my app to Apple and decided at the last minute that I needed to change the domain name, which breaks one feature of the app because it's relying explicitly on seeing the old domain name -- it doesn't see it anymore because of the changes made to my virtual hosts file.

tylerl
  • 1,160
  • 1
  • 19
  • 41

1 Answers1

1

You will need to use RedirectMatch for the regex capabilities:

RedirectMatch 301 ^((?!.*?excludedfile\.php).*)$ http://newdomain.com$1

This change will require you to restart the Apache.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Are you sure about this? I replaced my `Redirect` line with this and now everything just redirects to the homepage (`http://newdomain.com/` - nothing after the slash). – tylerl Jan 08 '14 at 07:50
  • Ah yes there was a typo, try updated rule and restart. – anubhava Jan 08 '14 at 07:51
  • Weird - now when I go to `http://olddomain.com/excludedfile.php` I get a 404 Error... trying to load any other location under `http://olddomain.com` results in an extra // before the file name - `http://olddomain.com/otherfile.php` becomes `http://newdomain.com//otherfile.php`... – tylerl Jan 08 '14 at 07:57
  • Made another update that will fix the double `//` problem and as you can see it is not redirecting `http://olddomain.com/excludedfile.php` now. – anubhava Jan 08 '14 at 08:08
  • Hmmmmm... Yeah but I'm still getting the weird 404 error... I guess it may be something else causing the 404 error? – tylerl Jan 08 '14 at 08:10
  • Right 404 is not because of this rule since rule is just skipping this to redirect to other website. – anubhava Jan 08 '14 at 08:12
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44757/discussion-between-tylerl-and-anubhava) – tylerl Jan 08 '14 at 08:13
  • @tylerl: Sorry I have to rush for a meeting, will be available online after an hour. – anubhava Jan 08 '14 at 08:21
  • 1
    For future visitors: The code above is perfect - the double slash issue AND the 404 error were because of my previous bad redirect code and my server requiring a custom DocumentRoot. – tylerl Jan 08 '14 at 09:39
  • @tylerl: Very nice comment to help out future visitors. I just came back online. – anubhava Jan 08 '14 at 09:41