cloudsidedev / cloudsidedev/appside

Improve structure of htaccess.j2

Open
#29 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
38
Forks
7
PR merge metrics
No merged PRs in 30d

Description

Looking at the [htaccess.j2 file](https://github.com/ttssdev/appflow/blob/5548d0f31ebf920c6039d22dd6b3dd7f1d058f8b/playbooks/roles/web/templates/wp_bedrock/htaccess.j2) and noticed a few issues:

* The iThemes Security block should be wrapped with a `` condition
* [`Options -Indexes`](https://github.com/ttssdev/appflow/blob/5548d0f31ebf920c6039d22dd6b3dd7f1d058f8b/playbooks/roles/web/templates/wp_bedrock/htaccess.j2#L242-L243) can be removed since it's now disabled by default, see 68b9e2ff1041bd9d391cb15d97d3e4ef08ae41b0
* [This block](https://github.com/ttssdev/appflow/blob/5548d0f31ebf920c6039d22dd6b3dd7f1d058f8b/playbooks/roles/web/templates/wp_bedrock/htaccess.j2#L245-L277) should be merged into one `` section
* The [WordPress rules ](https://github.com/ttssdev/appflow/blob/5548d0f31ebf920c6039d22dd6b3dd7f1d058f8b/playbooks/roles/web/templates/wp_bedrock/htaccess.j2#L281-L290) should be extended to support a Multisite flag.

Currently you have to add the Multisite rules to the site config which means they get added *before* all the other security checks. They should be the last one, just like the default WP rules.
The [rules for Multisite](https://github.com/WordPress/WordPress/blob/dd6da701b286579819cd6aa518aa2d7018efd759/wp-admin/includes/network.php#L560-L572) have a few variables which we need to define in the config. If one of them is set the provisioner would add the multisite site rules to the .htaccess file. Note that the multisite rules are a *replacement* of the default rules, so both versions shouldn't be added, which is currently the case.

Pseudo code (which can be improved once we know if this is possible):
```apache
# BEGIN WordPress

{% if item.value.multisite is defined %}
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^{{ item.value.multisite.subdir_match }}wp-admin$ {{ item.value.multisite.subdir_replacement_01 }}wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^{{ item.value.multisite.subdir_match }}(wp-(content|admin|includes).*) /{{{ item.value.multisite.subdir_replacement_12 }}} [L]
RewriteRule ^{{ item.value.multisite.subdir_match }}(.*\.php)$ /{{ item.value.multisite.subdir_replacement_12 }} [L]
RewriteRule . index.php [L]
{% else %}
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
{% endif %}

# END WordPress
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.