# \[SOLVED\] .htaccess DAV redirects lose https reverse proxy

**URL:** <https://help.nextcloud.com/t/solved-htaccess-dav-redirects-lose-https-reverse-proxy/138922>\
**Category:** 📦 Appliances (Docker, Snappy, VM, NCP, AIO)\
**Tags:** docker\
**Created:** [May 11, 2022, 6:28pm UTC](https://help.nextcloud.com/t/solved-htaccess-dav-redirects-lose-https-reverse-proxy/138922 "2022-05-11T18:28:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsthejb](https://help.nextcloud.com/user_avatar/help.nextcloud.com/itsthejb/32/14462_2.png) [@itsthejb](https://help.nextcloud.com/u/itsthejb)\
**Post date:** [May 11, 2022, 6:28pm UTC](https://help.nextcloud.com/t/solved-htaccess-dav-redirects-lose-https-reverse-proxy/138922/1 "2022-05-11T18:28:11Z")

</div>

Hi everyone,

I’ve got a long standing issue with my dockerized Nextcloud set up, which I’m currently working around, but it would be great to solve it “properly”:

Basically, the standard [`.htaccess` rewrite rules](https://github.com/nextcloud/server/blob/master/.htaccess#L91-L102) for the `dav` endpoints lose `https`. So if I do:

```auto
$ wget https://<my domain>/.well-known/carddav 2>&1 | grep Location:

```

I’ll get:

```auto
Location: http://<my domain>/remote.php/dav/ [following]

```

This will then fail.

In order to work around this, I’m manually editing the rules to be:

```auto
  RewriteRule ^$ https://%{SERVER_NAME}/remote.php/webdav/ [L,R=302]
  RewriteRule ^\.well-known/carddav https://%{SERVER_NAME}/remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav https://%{SERVER_NAME}/remote.php/dav/ [R=301,L]
  RewriteRule ^remote/(.*) https://%{SERVER_NAME}/remote.php [QSA,L]

```

Then everything works fine. However this is a hack, so there must be something else that’s wrong.

In my case, I’m using Cloudflare tunnels to provide the SSL, but I had this problem previously when I just had my own Apache reverse proxy.

Can anyone help?

Thanks!

---

<div class="post-metadata">

**Author:** ![itsthejb](https://help.nextcloud.com/user_avatar/help.nextcloud.com/itsthejb/32/14462_2.png) [@itsthejb](https://help.nextcloud.com/u/itsthejb)\
**Post date:** [May 17, 2022, 9:29am UTC](https://help.nextcloud.com/t/solved-htaccess-dav-redirects-lose-https-reverse-proxy/138922/2 "2022-05-17T09:29:29Z")

</div>

I’ve now seen: [https://docs.nextcloud.com/server/latest/admin\_manual/configuration\_server/reverse\_proxy\_configuration.html#apache2](https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/reverse_proxy_configuration.html#apache2).

Seems I’ll try re-implementing that using a page rule in Cloudflare, and remove my customisation

---

<div class="post-metadata">

**Author:** ![leogaggl](https://help.nextcloud.com/user_avatar/help.nextcloud.com/leogaggl/32/56742_2.png) [@leogaggl](https://help.nextcloud.com/u/leogaggl)\
**Post date:** [December 14, 2023, 1:59am UTC](https://help.nextcloud.com/t/solved-htaccess-dav-redirects-lose-https-reverse-proxy/138922/3 "2023-12-14T01:59:43Z")

</div>

I have the same problem with using Traefik/Docker and the stock standard .htaccess from Nextcloud.

Traefik labels from docker-compose.yml

```auto
- "traefik.http.middlewares.nextcloud_redirectregex.redirectregex.permanent=true"
- "traefik.http.middlewares.nextcloud_redirectregex.redirectregex.regex='https:\\(.*)/.well-known/(card|cal)dav'"
- "traefik.http.middlewares.nextcloud_redirectregex.redirectregex.replacement=https://$${1}/remote.php/dav/"

```

Using if I run

`wget https://<my domain>/.well-known/carddav 2>&1 | grep Location:`

I still get

`Location: http://<my domain>/remote.php/dav/ [following]`

which means that caldav clients can not connect.

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 14, 2024, 2:32pm UTC](https://help.nextcloud.com/t/solved-htaccess-dav-redirects-lose-https-reverse-proxy/138922/4 "2024-12-14T14:32:38Z")

</div>


