# Troubles with Apache reverse proxy while trying to run CMS in a subdirectory

**URL:** https://community.xibo.org.uk/t/troubles-with-apache-reverse-proxy-while-trying-to-run-cms-in-a-subdirectory/25399
**Category:** CMS Installation
**Created:** [July 15, 2021, 4:04pm UTC](https://community.xibo.org.uk/t/troubles-with-apache-reverse-proxy-while-trying-to-run-cms-in-a-subdirectory/25399 "2021-07-15T16:04:15Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![phanku](https://community.xibo.org.uk/user_avatar/community.xibo.org.uk/phanku/32/11628_2.png) [@phanku](https://community.xibo.org.uk/u/phanku)
#### Post date: [July 16, 2021, 4:29pm UTC](https://community.xibo.org.uk/t/troubles-with-apache-reverse-proxy-while-trying-to-run-cms-in-a-subdirectory/25399/2 "2021-07-16T16:29:04Z")

</div>

Hello,

Thank you for those who viewed this posting. We have figured the issue with attempting to move the CMS down a directory, off of the web root, using an Apache reverse proxy.

I am submitting my solution here as I know that other people look at the posts here for support.

**- What was wrong**

The issue with attempting to move the CMS down a directory is that the entrypoint.sh file within the CMS Docker container does handle using the `CMS_ALIAS` from the config.env file to modify the `.htaccess` file within the `/var/www/cms/web/` directory. However, the entrypoint.sh file does not complete all of the actions that would be needed to be done on the `.htaccess` file if a person has set the `CMS_ALIAS` configuration within the config.env file.

The entrypoint.sh file will uncomment and update the RewriteBase directive in the `.htaccess` file with the value of the `CMS_ALIAS` set within the config.env file but it does not modify the rewrite conditions for the API end points which it would have to do so if the CMS has moved down a directory.

Here is what the `.htaccess` file will look like in the Docker container once the container is spun up and a value is set on the `CMS_ALIAS` variable. The below example is with the assumption that the `CMS_ALIAS` was set to `/cms`.

> RewriteEngine On  
> RewriteBase /cms
> 
> RewriteCond %{HTTP:Authorization} .+  
> RewriteRule .\* - [E=HTTP\_AUTHORIZATION:%{HTTP:Authorization}]
> 
> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteCond %{REQUEST\_URI} ^/api/authorize/.\*$  
> RewriteRule ^ api/authorize/index.php [QSA,L]
> 
> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteCond %{REQUEST\_URI} ^/api/.\*$  
> RewriteRule ^ api/index.php [QSA,L]
> 
> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteCond %{REQUEST\_URI} ^/maint/.\*$  
> RewriteRule ^ maint/index.php [QSA,L]
> 
> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteCond %{REQUEST\_FILENAME} !-d  
> RewriteCond %{REQUEST\_FILENAME} !.(css|js|png|jpg)$  
> RewriteCond %{REQUEST\_URI} !^/dist/._$  
> RewriteCond %{REQUEST\_URI} !^/theme/._$  
> RewriteRule ^ index.php [QSA,L]

As you can see in the rewrite conditions for the API access points that the rewrite condition is never matched due to the assertion of the start of the line in the regex condition for the API endpoints.  
The rewrite conditions will match only when the rewrite base is not used.

**- How to fix the issue**

What needs to happen is to remove the `^` symbols in the rewrite conditions for the API end points so they look below.

> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteCond %{REQUEST\_URI} /api/authorize/.\*$  
> RewriteRule ^ api/authorize/index.php [QSA,L]
> 
> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteCond %{REQUEST\_URI} /api/.\*$  
> RewriteRule ^ api/index.php [QSA,L]

The issue is that the `.htaccess` file needs to be in the spun up CMS Docker container.

This is how we solved the issue. I have no idea if this would be the correct method or not so if you know a better way to solve this issue please contact me.

1. First we obtained a copy of the `.htaccess` file from the spun up Docker container. We pulled a copy of the file when the `CMS_ALIAS` in the config.env was active.
2. We updated the `.htaccess` file to correct for the issue.
3. We placed the modified `.htaccess` file in our persistent volume for the CMS, `/shared/cms/web/`.
4. We modified the docker-compose.yml file and added a specific file for the `/var/www/cms/web/` directory within the container. What we added was the reference to the modified `.htaccess` file. See example below.

> cms-web:  
> image: xibosignage/xibo-cms:release-2.3.10  
> volumes:  
> - “./shared/cms/custom:/var/www/cms/custom:Z”  
> - “./shared/backup:/var/www/backup:Z”  
> - “./shared/cms/web/theme/custom:/var/www/cms/web/theme/custom:Z”  
> - “./shared/cms/library:/var/www/cms/library:Z”  
> - “./shared/cms/web/userscripts:/var/www/cms/web/userscripts:Z”  
> - “./shared/cms/ca-certs:/var/www/cms/ca-certs:Z”  
> - “./shared/cms/web/.htaccess:/var/www/cms/web/.htaccess:Z”

1. Spin down and up the containers and everything should work after that.

I hope this helps someone someday.

---

_[View the full topic](https://community.xibo.org.uk/t/troubles-with-apache-reverse-proxy-while-trying-to-run-cms-in-a-subdirectory/25399)._
