RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(template/)
RewriteRule . /index.php [L]
For this to work in the subdirectory, you need to:
- Remove the
RewriteBase
directive entirely. (It's not being used anyway currently.)
- Remove the slash prefix on the substitution string in the last rule.
Additionally:
- The parenthesis in the last condition (
RewriteCond
directive) are superfluous. And this condition should be first, not last (for optimisation).
- The
<IfModule>
wrapper is superfluous and should be removed. (Assuming you also have a closing </IfModule>
"tag"?)
Options +FollowSymLinks
is also superfluous given the preceding Options All
directive.
- The
RewriteRule
pattern in the HTTP to HTTPS redirect (ie. (.*)
) does not need to be capturing.
Bringing the above points together, we have:
Options All -Indexes
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !template/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
This will now work regardless of the directory the script is installed in (root or subdirectory).