# mod_rewrite - SubDomain to Directories



## Leander (May 20, 2015)

Hi,

I'm trying to achieve, that a subdomain is re-written to directories like:

https://DAViCal.WM-01.MyDomain.Local/caldav.php/Username/Service
to
https://Service.Username.DAViCal.WM-01.MyDomain.Local


```
<ifModule mod_rewrite.c>
  <If "(%{SERVER_NAME} =~ m#^.*\..*\.DAViCal.WM-01.*$#i)">
    RewriteEngine on
    RewriteCond %{HTTP_HOST}  "^.*\..*\.DAViCal.WM-01.*$" [NC]
    RewriteCond %{REQUEST_URI} ^/caldav.php/?$
    RewriteRule ^(.*)\.(.*)\.(DAViCal.WM-01.*)$ https://$3/$2/$1 [L,NC,R]
  </If>
</IfModule>
```
Unfortunately the RewriteRule does not do what I want and it is hard to debug. Maybe you have an idea of the solution?


----------



## Leander (May 21, 2015)

Ok, I got it partially working. All devices connect to the DAViCal service. But they can not write back any data, like a new appointment. It seems like my RewriteRule doesn't work entirely. Any ideas why WebDAV is not being written back with this rule?


```
<IfModule mod_proxy.c>
  SSLProxyEngine on
  <ifModule mod_rewrite.c>
    <If "(%{SERVER_NAME} =~ m#^.*\..*\.davical\..*$#i)">
      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.DaviCal.WM-01.MyDomain.Local(.*) [NC]
      RewriteRule ^(.*) https://DaviCal.WM-01.MyDomain.Local/htdocs/caldav.php/%2/%1 [P,L,NC]
    </If>
  </IfModule>
</IfModule>
```

When trying to add a new appointment, I see this in my httpd-access.log of iOS

```
192.168.10.35 - - [21/May/2015:03:37:12 +0200] "PUT /davical/caldav.php/leander/calendar/D529853C-D107-4490-9F3E-C0940DB1B75B.ics HTTP/1.1" 201 - "-" "iOS/8.3 (12F70) dataaccessd/1.0"
```
and I see this in the httpd-access.log of Thunderbird

```
192.168.10.233 - - [21/May/2015:03:37:53 +0200] "PUT /02571881-8f7e-2441-ae70-997faf6ec35a.ics HTTP/1.1" 405 - "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 Lightning/3.3.2"
```
I've also tried

```
<IfModule mod_proxy.c>
  SSLProxyEngine on
  <ifModule mod_rewrite.c>
    <If "(%{SERVER_NAME} =~ m#^.*\..*\.davical\..*$#i)">
      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.DaviCal.WM-01.MyDomain.Local(.*) [NC]
      RewriteRule ^(.*)$ https://DaviCal.WM-01.MyDomain.Local/htdocs/caldav.php%3/%2/%1 [E=WEBDAV:true,E=REDIRECT_WEBDAV:true,E=REMOTE_USER:%{HTTP:Authorization},P,L,NC,QSA]
    </If>
  </IfModule>
</IfModule>
```
Unfortunately without any success ... ;/


----------



## Leander (May 21, 2015)

Any idea why DAV data can not be transfered with the current RewriteRule?


----------

