0

I have a Drupal app at the default virtual host example.org running on Debian 8. I also have a separate application with a virtual host set to send requests for jones-store.example.org to another directory. That works as expected.

I also have a CNAME of jones.example.org that should point to example.org/jones. I cannot see how that would work because the Apache virtual host is expecting to send requests for this subdomain to a physical place on the server. But as you know, Drupal is handling these routes itself.

So I started searching and believe that .htaccess should redirect this.

  RewriteCond %{HTTP_HOST} ^jones\.example\.com$ [NC]
  RewriteRule ^(.*)$ https://example.com/jones [L,R=302]

You can probably tell what's going to happen. It appears that the virtual host is checked first and the virtual host beats out the .htaccess rule.

I've tried the following rule:

RewriteCond %{HTTP_HOST}=jones.example.com [NC]

But it also catches the virtual host first.

I disabled my jones-store.example.org temporarily and the htaccess "catches" but does not redirect to the url.

But my main question is how could I do this redirect with this virtual host?

3
  • Check if the .htaccess is being read. And use AllowOverride All instead of AllowOverride None.
    – jarvis
    Apr 27, 2016 at 0:27
  • Yes, you got me to thinking. it seems that the virtual host name is first, so I should put the Rules in the .htaccess of that target. And I can confirm that .htaccess is being read when i put something goofy in it.
    – sam452
    Apr 27, 2016 at 15:35
  • Yes, altering the .htaccess for the virtual-host target is the approach that works. And the first Rewrite rule set above works. If you can put that in the form of an answer, I'll gladly accept it.
    – sam452
    Apr 27, 2016 at 15:45

0

You must log in to answer this question.

Browse other questions tagged .