DirectAdmin Knowledge Base and Support

DirectAdmin is a web panel for a simple administration of both virtual and dedicated servers. DirectAdmin is faster, safe and more powerful than any other CP. And we know how to customize and support it.

Does OpenLiteSpeed support .htaccess and rewrite rules?

| 18:14:43 06.05.2019

Yes, OpenLiteSpeed (OLS) supports mod_rewrite rules in .htaccess file, but currently it is done with some restrictions. The mod_rewrite rules from .htaccess are loaded by OLS at a start time only.

Practically it means, every time you modify rewrite rules in .htaccess file via FTP/SSH/sFTP you need to reload OpenLiteSpeed. The web server won't either read your changes or find new .htaccess file until you reload/restart it. 

Are there any options?

Directadmin File Manager

A reload of OpenLiteSpeed is possible from an user level in DirectAdmin, it's auto-done in a File Manager at a .htaccess edit time. So, once you modified a .htaccess file and saved it, directadmin will reload OLS so that new rewrite rules could take effect.

Reload OLS with crontab

If you still want to modify .htaccess file via FTP, then you can set up a cron task to do a graceful reload of OpenLiteSpeed.

When doing a /usr/local/lsws/bin/lswsctrl restart a graceful reload with a zero downtime will be preformed (if all rewrite rules are done without errors and typos).

Directadmin developers offer the following solution.

Here is a line for crontab, do not try to run it in a shell:

*/3 * * * * root if ! find /home/*/domains/*/*_html/ -maxdepth 2 -type f -newer /usr/local/lsws/cgid -name '.htaccess' -exec false {} +; then /usr/local/lsws/bin/lswsctrl restart; fi

To get the crontask installed run the following command as root:

echo '*/3 * * * * root if ! find /home/*/domains/*/*_html/ -maxdepth 2 -type f -newer /usr/local/lsws/cgid -name ".htaccess" -exec false {} +; then /usr/local/lsws/bin/lswsctrl restart; fi' > /etc/cron.d/openlitespeed_htaccess_scan 

Check the file and make sure it was populated with the correct line:

cat /etc/cron.d/openlitespeed_htaccess_scan

This way a crontask to search recently modified .htaccess files and restart OpenLiteSpeed will be set up.

Possible issues

If mod_rewrite rules do not work as expected you might check and see /var/log/httpd/error_log for possible errors, e.g.:

2019-05-06 19:11:02.548722 [ERROR] [(null)] rewrite: invalid rewrite condition while parsing: RewriteCond %{HTTP_HOST} ! ^ [NC]
2019-05-06 19:11:02.553827 [ERROR] [(null)] rewrite: invalid rewrite condition while parsing: RewriteCond %{HTTP_HOST} ! ^ [NC]

The logs might give you tips on what is wrong with the rules. 


About Us
We are a team of professionals, and specialize in installation, configuring and managing of remote virtual and dedicated servers powered by Linux/Unix-like OS with DirectAdmin. We support various sets of software, including web-servers Apache, Nginx; internet domain name servers Bind, PowerDNS; mail-servers with POP3, IMAP and SMTP, FTP-servers, etc. After years of working through the most complex server challenges our team has gathered valuable experience and universal solutions suitable for everyday tasks. We are here to lend you a helping hand and take care of your servers in order to let you have enough time to do more of what you love.

All of the information and data on this site is for informational purposes only and is provided for the convenience of the user.
Powered by: Amiro.CMS - Free edition