.htaccessapache2setenvhttp-hostifdefine

SetEnvIf HTTP_HOST not working


I can't get it work this part of .htaccess, the IfDefine never runs. What am I doing wrong, setenvif mod is enabled.

RewriteBase /

SetEnvIf HTTP_HOST ^localhost$ local
<IfDefine local>
  RewriteBase /codeigniter-app/
</IfDefine>

SetEnvIf HTTP_HOST ^testing.alex.com$ testing
<IfDefine testing>
    RewriteBase /app/
</IfDefine>

This is based on: With mod_rewrite can I specify a RewriteBase within a RewriteCond?

Edit: Any other way to accomplish the above?


Solution

  • My answer if that Apache doesn't allow you to do what you are trying to do here, but that's because AFAIK you don't need to do this to do what you really need to do.

    It seems as if you are trying to create a local environment that in configuration terms mirrors your (remote) server-based test environment. However you are confusing the URI namespace and the file system namespace and in Apache Server these are quite different. For example the <Location> directive operates on the former and the <Directory> directive operates on the latter. .htaccess sort of cut across both so you need to understand when a parameter operates on one or the other.

    For example, I have a shared service account which service a number of subdomains *.ellisons.org.uk -- for example my blog is on http://blog.ellisons.org.uk/. I develop on an Ubuntu laptop and a VM that mirrors the LAMP/suPHP configuration that my service provider operates (but I have root access and can see the rewrite logs, etc. on the VM) I statically allocate IP addresses in my 192.168.1.0/24 private address space and have /etc/hosts symonyms for

    127.0.1.1      ... blog.ellisons.org.home forum.ellisons.org.home ...
    192.168.1.250  ... blog.ellisons.org.vm ...
    

    But other than this the URI space is identical,so blog.ellisons.org.XX/themes/terry/all.css loads my css from my server,laptop or VM depending on whether XX=uk,home,vm

    However the docroot on my laptop is Debian standard /var/www, but on the other two it is /websites/LinuxPackage02/el/li/so/ellisons.org.uk/public_html (my hosters naming convention). Yet my application including .htaccess files is identical, and the only way that these reflect this multiple use is in regexps where I using as a regexp to match %{HTTP_HOST} (\w+)\.ellisons.\org\.(?:uk|home|vm).

    So to your example:

    So to summarise, with a little bit of thought you can make your configurations logically identical as Apache offers -- isn't that better than trying to botch in conditional execution in a way that was never designed into the product?