Why Does .htaccess Redirect Work but DirectAdmin Site Redirection Does Not?

iPwsite

Verified User
Joined
May 9, 2020
Messages
27
Hello DirectAdmin Community,

I'm having an issue where the DirectAdmin Site Redirection feature is not working as expected for my domain, example.com, but a manual .htaccess rule works fine. I need help understanding why this is happening and how to fix the Site Redirection feature.

My Setup​

  • Domain: example.com
  • Server IP: 192.168.1.3
  • DirectAdmin Version: Latest
  • Web Server: Apache
  • SSL: Let’s Encrypt certificate installed via DirectAdmin, covering example.com
  • Website: Used for a small business

Issue​

  • Problem: example.com works. www.example.com does not work consistently with HTTPS, and https://example.com sometimes fails. I want to redirect all traffic (http://, www, etc.) to https://example.com.
  • DirectAdmin Site Redirection: I set up redirects in DirectAdmin under Account Manager > Site Redirection:
  • .htaccess Fix: I added the following to .htaccess in public_html, and it works perfectly:
    RewriteEngine On<br>RewriteCond %{HTTPS} off [OR]<br>RewriteCond %{HTTP_HOST} ^www\. [NC]<br>RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]<br>
  • DNS: Confirmed with my domain provider that DNS is correct, pointing to my nameservers, with A records for both example.com and www.example.com set to 192.168.1.3.

Questions​

  1. Why does the DirectAdmin Site Redirection feature fail to redirect www and HTTP traffic to https://example.com, while the .htaccess rule works?
  2. Is there a specific configuration in DirectAdmin (e.g., Apache virtual host settings, rewrite module, or SSL settings) that I need to check or enable?
  3. Could this be related to how DirectAdmin handles Let’s Encrypt certificates or Apache configurations?

Additional Notes​

  • I’ve updated the Let’s Encrypt certificate to include www.example.com.
  • Tested in incognito mode to rule out caching issues.
  • My hosting provider manages the nameservers.
Any insights or suggestions on fixing the Site Redirection feature would be greatly appreciated! I’d prefer to use DirectAdmin’s built-in tool to avoid manual .htaccess edits for simpler management.


Thank you!
 


As far as I know DirectAdmin under Account Manager > Site Redirection can redirect only http://example.com/anything to http://another-example.com/anything

For redirecting HTTP -> HTTPS you should choose "Force SSL with https redirect" on a domain management page

poralix.png
 
As far as I know DirectAdmin under Account Manager > Site Redirection can redirect only http://example.com/anything to http://another-example.com/anything

For redirecting HTTP -> HTTPS you should choose "Force SSL with https redirect" on a domain management page

If you have an SSL certificate for the domain, you can also use the option in the SSL page to force a HTTPS redirect. I believe you'll get errors if you have a force redirect on and no certificate installed.

Pic taken from my production server and I use this as some of my software refuses to operate properly without HTTPS.


1759860912372.png
 
Hello DirectAdmin Community,

I'm having an issue where the DirectAdmin Site Redirection feature is not working as expected for my domain, example.com, but a manual .htaccess rule works fine. I need help understanding why this is happening and how to fix the Site Redirection feature.

My Setup​

  • Domain: example.com
  • Server IP: 192.168.1.3
  • DirectAdmin Version: Latest
  • Web Server: Apache
  • SSL: Let’s Encrypt certificate installed via DirectAdmin, covering example.com
  • Website: Used for a small business

Issue​

  • Problem: example.com works. www.example.com does not work consistently with HTTPS, and https://example.com sometimes fails. I want to redirect all traffic (http://, www, etc.) to https://example.com.
  • DirectAdmin Site Redirection: I set up redirects in DirectAdmin under Account Manager > Site Redirection:
  • .htaccess Fix: I added the following to .htaccess in public_html, and it works perfectly:
    RewriteEngine On<br>RewriteCond %{HTTPS} off [OR]<br>RewriteCond %{HTTP_HOST} ^www\. [NC]<br>RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]<br>
  • DNS: Confirmed with my domain provider that DNS is correct, pointing to my nameservers, with A records for both example.com and www.example.com set to 192.168.1.3.

Questions​

  1. Why does the DirectAdmin Site Redirection feature fail to redirect www and HTTP traffic to https://example.com, while the .htaccess rule works?
  2. Is there a specific configuration in DirectAdmin (e.g., Apache virtual host settings, rewrite module, or SSL settings) that I need to check or enable?
  3. Could this be related to how DirectAdmin handles Let’s Encrypt certificates or Apache configurations?

Additional Notes​

  • I’ve updated the Let’s Encrypt certificate to include www.example.com.
  • Tested in incognito mode to rule out caching issues.
  • My hosting provider manages the nameservers.
Any insights or suggestions on fixing the Site Redirection feature would be greatly appreciated! I’d prefer to use DirectAdmin’s built-in tool to avoid manual .htaccess edits for simpler management.


Thank you!
This issue likely occurs because DirectAdmin’s Site Redirection tool manages redirects at the virtual host (Apache configuration) level, which doesn’t always apply consistently across SSL and non-SSL contexts—especially when separate VirtualHost entries exist for example.com and www.example.com. The .htaccess method works because it runs at the application level and is processed after the server receives the request, so it captures all variations (http, https, www, and non-www) reliably.

To fix the Site Redirection feature, make sure:

  • Both example.com and www.example.com are covered under the same Let’s Encrypt certificate in DirectAdmin.
  • The Redirect option is added under both HTTP and HTTPS vhosts (DirectAdmin sometimes only writes it to one).
  • mod_rewrite is enabled in Apache.
  • If using Custom HTTPD configurations, ensure there’s no conflicting rewrite rule overriding the DirectAdmin redirect.
In short, .htaccess works because it’s universal across all entry points, while DirectAdmin’s redirection may fail due to vhost or SSL scope. Reissuing the SSL cert for both domains and applying the redirect under both vhosts usually resolves the inconsistency.
 
This issue likely occurs because DirectAdmin’s Site Redirection tool manages redirects at the virtual host (Apache configuration) level

The issue occurs because the DirectAdmin’s Site Redirection tool uses a Redirect directive of Apache Module mod_alias, which does not allow conditional redirecting from HTTP -> HTTPS. You will get an infinite loop if you try to redirect http://www.example.com/ to https://www.example.com/ with the DirectAdmin’s Site Redirection tool .

p.s. Please share human verified solutions, do not post solutions generated by AI.
p.p.s Why am I under an impression you are the same guy who posted under the nick-name iPwsite?
 
Back
Top