Add custom rewrite rules for a subdomain

goftari

Verified User
Joined
Jun 18, 2022
Messages
10
Dear forum members,
I am not much familiar with DirectAdmin and need to add a RewriteRule to proxy specific directories under a subdomain to another server.
I am using LiteSpeed v5.4 in which ProxyPass cannot be defined, so I am inserting my RewriteCond lines and RewriteRule in the httpd.conf file located in /usr/local/directadmin/data/users/user1/ (user1 is the main domain user) where the config is containing all the subdomains virtual hosts config.
I inserted my code inside the following tag under the desired virtual host.
<IfModule Litespeed>
CacheRoot lscache
</IfModule>

Everything works correctly until any changes are made to subdomains from DirectAdmin and the aforementioned config file gets rewritten by DirectAdmin.
Any help would be appreciated!
Regards
 
Hello,

You shouldn't modify httpd.conf file directly. Connect to DirectAdmin as admin and insert your custom code into a virtual host on the page "Custom HTTPD Configurations". This way will you have a protection from your customization to be lost.
 
Hello,

You shouldn't modify httpd.conf file directly. Connect to DirectAdmin as admin and insert your custom code into a virtual host on the page "Custom HTTPD Configurations". This way will you have a protection from your customization to be lost.
Thanks @zEitEr
But I was looking to use CUSTOM tags to place the customization inside specific segment of code. But was not able to use CUSTOM tag properly.
For instance, how may I add url rewrite to redirect HTTP to HTTPS traffic just under virtual host config for :80 virtual host entry of the sub-domain?
 
There are at least 2 approaches:

1. Add your subdomain as a domain with its own public_html. Use DirectAdmin's native option for redirecting traffic from HTTP to HTTPs.
2. Use IF-statements in CUSTOM section of DirectAdmin, e.g.:

Code:
# Check subdomain name:
|*if SUB="zzzz"|
   |?SSL_REDIRECT_HOST=1|
|*endif|
# Disable redirect if already HTTPS is used
|*if SSL_TEMPLATE="1"|
   |?SSL_REDIRECT_HOST=|
|*endif|
# Redirect to HTTPS for a subdomain
|*if SSL_REDIRECT_HOST!=""|
      Redirect / https://|SUB|.|DOMAIN|/
|*endif|

where zzzz should be replaced by your real domain name.

Something like this.
 
There are at least 2 approaches:

1. Add your subdomain as a domain with its own public_html. Use DirectAdmin's native option for redirecting traffic from HTTP to HTTPs.
2. Use IF-statements in CUSTOM section of DirectAdmin, e.g.:

Code:
# Check subdomain name:
|*if SUB="zzzz"|
   |?SSL_REDIRECT_HOST=1|
|*endif|
# Disable redirect if already HTTPS is used
|*if SSL_TEMPLATE="1"|
   |?SSL_REDIRECT_HOST=|
|*endif|
# Redirect to HTTPS for a subdomain
|*if SSL_REDIRECT_HOST!=""|
      Redirect / https://|SUB|.|DOMAIN|/
|*endif|

where zzzz should be replaced by your real domain name.

Something like this.
Thanks for your reply.
Does the Redirect command accepts regex like:
Redirect (.*) https://|SUB|.|DOMAIN|/$1
 
Back
Top