What is the best way to deal with .htaccess files in subdirectories?
From what I understand, OpenLiteSpeed only reads the .htacess files in the main directory of the website.
Using the example of PrestaShop, there are several .htaccess files listed in subdirectories. From a search, these are the files I could find:
- ./translations/.htaccess
- ./translations/cldr/.htaccess
- ./themes/.htaccess
- ./themes/classic/config/.htaccess
- ./vendor/.htaccess
- ./vendor/tecnickcom/tcpdf/tools/.htaccess
- ./vendor/mrclay/minify/min/.htaccess
- ./vendor/mrclay/minify/min/builder/.htaccess
- ./vendor/prestashop/smarty/.htaccess
- ./cache/.htaccess
- ./.htaccess
- ./override/.htaccess
- ./classes/.htaccess
- ./mails/.htaccess
- ./controllers/.htaccess
- ./modules/.htaccess
- ./app/.htaccess
- ./upload/.htaccess
- ./config/.htaccess
- ./config/xml/.htaccess
- ./js/.htaccess
- ./admin877zpdps0/.htaccess
- ./admin877zpdps0/import/.htaccess
- ./admin877zpdps0/export/.htaccess
- ./admin877zpdps0/backups/.htaccess
- ./docs/.htaccess
- ./docs/csv_import/.htaccess
- ./src/.htaccess
- ./pdf/.htaccess
- ./tools/.htaccess
- ./tools/parser_sql/.htaccess
- ./tools/htmlpurifier/.htaccess
- ./tools/profiling/.htaccess
- ./bin/.htaccess
- ./download/.htaccess
- ./localization/.htaccess
- ./img/.htaccess
I also understand the directory option cannot be read in the main .htaccess file so I can't move everything to a single file.
I thought of the following solutions:
- Move all the file properties to Contextes within the WebAdmin panel.
- Use rewrite rules in the main .htaccess file for the information in the .htaccess subdirectory files
Comments
Deny from all
And these two directives are not read by OpenLiteSpeed, as OpenLiteSpeed has its own mechanism to deny access.
But if there are any important rules in sub-directories contexts are your best chance. If I take an example of WordPress installation in sub-directory such as "cyberpanel"
Then my context config would look like:
location /home/example.com/public_html/cyberpanel
allowBrowse 1
rewrite {
enable 1
inherit 0
RewriteFile /home/example.com/public_html/cyberpanel/.htaccess
}
addDefaultCharset off
}
And rewrite rules in WordPress sub-directory
# BEGIN WordPress
RewriteEngine On
RewriteBase /cyberpanel/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cyberpanel/index.php [L]
# END WordPress
Coming back to Prestashop, important rules are already in doc root of PrestaShop installation, but if PrestaShop is in sub-directory you can use contexts.
But if you think there is any important .htaccess file in sub-directory with PrestaShop, you can surely use contexts.
CyberPanel
Blog
So for PrestaShop
The file /translations/.htaccess has the following rules: My Context in the vHost Conf would be: The file /translations/cldr/.htaccess has the following rules:
My Context in the vHost Conf would be: I someone would not be able to access the translation folder in the browser but they could access the translations/cldr folder. After applying this context, when trying to access domain/translations, I am hit with a 403 error. Before, it was clearly a 404 error. Is this set up correct?
The file /themes/.htaccess has the following rules: The issue is OpenLiteSpeed does not recognize FilesMatch. I believe I have to use a Perl regular expression in the Static Context for the URI. Would the context look like the one below:
The file /vendor/mrclay/minify/min/.htaccess has the following rules: Woudl it be better to create a static context with the information or put the information in the main .htaccess file?
Example static context:
Or something is not working as expected on your end?
CyberPanel
Blog
Otherwise, you will have to go into different files later and create many other contexts.
CyberPanel
Blog
https://blog.cyberpanel.net/2018/04/07/how-to-write-rewrite-rules-for-openlitespeed/
Under the heading: WordPress in subdirectory
CyberPanel
Blog
From the PrestaShop file /upload/.htaccess
The PrestaShop directory /admin: I copied the rewrite rules into a Context file but now when I visit the admin panel, I get a 500 error:
From v1.7 ( 1.7 is in RC ) onwards this conversion is not needed.
For the rest of directives that you have mentioned they are ignored by OpenLiteSpeed, but they will not cause the server to stop and they will be ignored.
You will need to use OpenLiteSpeed to set extra headers using contexts and regular expressions the same way you did earlier.
CyberPanel
Blog
.htaccess
Options -Indexes
Static Context
autoIndex 0
.htaccess
DirectoryIndex index.php index.html index.htm
Static Context
indexFiles index.php index.html index.htm
.htaccess
AddType image/svg+xml svg svgz
Static Context
addMIMEType image/svg+xml svg svgz
.htaccess Static Context .htaccess Static Context I currently do not understand how to set these parameters in OLS. Any assistance on them would be appreciated.
.htaccess Static Context I see that headers can be set, the issue I am having is the headers can only be set for certain file types rather than all files in the directory. I do not know how to create file level rules. A Static Context refers to directory level rules, correct?
.htaccess I am also not sure if this option is even necessary.
for example
RewriteRule ^/.*\.(log|ini|tpl|txt)$ - [F]