2

Assume we have 2 domains.

www.my-domain.com
www.mydomain.com

As Standard, we have a redirection from .mydomain.com/ to .my-domain.com/ via

(mydomain.conf)
<Virtualhost *:80>
  ServerName mydomain.com
  ServerAlias mydomain.com *.mydomain.com

  RewriteEngine on
  RewriteCond %{HTTP_HOST} (.+\.)?mydomain\.com(\/.+)?$ [NC]
  RewriteRule (.*) http://%1my-domain.com$2$1 [R=301]
</VirtualHost>

But now, due to backwards compability, we have one special URL "www.mydomain.com/special/task.php" which needs to be served directly and should not be redirected.

What i am trying to do ist something like this:

(mydomain.conf)
<Virtualhost *:80>
  ServerName mydomain.com
  ServerPath /special/
  DocumentRoot /var/www/special/
</VirtualHost>

<Virtualhost *:80>
  ServerName mydomain.com
  ServerAlias mydomain.com *.mydomain.com

  RewriteEngine on
  RewriteCond %{HTTP_HOST} (.+\.)?mydomain\.com(\/.+)?$ [NC]
  RewriteRule (.*) http://%1my-domain.com$2$1 [R=301]
</VirtualHost>

But this wont work. What am i doing wrong or is this even possible? What do i have to do differently?

Hugie
  • 137
  • 6

1 Answers1

1

You should add another RewriteCond behind your existing one to implement this exception. Like this:

RewriteCond %{REQUEST_URI} !=/special/task.php [NC]

Note, that by default, all RewiteConds are connected with logical AND. So the RewriteRule is triggered only if all RewriteConds evaluate to true.

Kamil Šrot
  • 333
  • 1
  • 3
  • 10
  • How do i add the DocumentRoot then? Just add it aftwerwards and it will be used, since the second RewriteRule does not redirect the call? – Hugie Dec 09 '13 at 12:24
  • Sry, i forgot to think. I will add this, and this Condition eliminates the following Redirection if its false(!true) AND then serves the content as defined by the embedded DocumentRoot. – Hugie Dec 09 '13 at 12:28