Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
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 9 '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 9 '13 at 12:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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