
The .htaccess file is the backbone of URL management on Apache Web Server — which powers every DirectAdmin hosting plan. Whether you need to redirect old pages to new URLs, force HTTPS, or clean up your URL structure, this guide covers every .htaccess redirect method with copy-paste-ready code examples.
Editing .htaccess on DirectAdmin
There are two main ways to edit .htaccess on DirectAdmin:
- File Manager: Go to DirectAdmin → Files → File Manager → public_html → click .htaccess → Edit
- FTP: Connect via FileZilla and edit the .htaccess file in the domain root directory
Important: .htaccess is a hidden file (dot file) on Linux. If using FTP, enable "Show hidden files" first. In FileZilla, go to Server → Force showing hidden files.
301 vs 302 Redirect: Key Differences
Understanding the difference is essential before choosing a redirect type:
- 301 Moved Permanently — The old URL is permanently moved. Google transfers ~90–99% of SEO link equity to the new URL. Use for permanent moves.
- 302 Found (Temporary) — A temporary redirect. Google keeps the old URL in its index. Use only for temporary redirects.
Redirect HTTP to HTTPS
The most critical redirect in modern web hosting — forcing all traffic to use HTTPS:
For servers behind a proxy or load balancer, use the forwarded protocol header instead:
Redirect www to non-www (and vice versa)
www → non-www (recommended for most sites)
non-www → www
Redirect a Specific Page
For redirecting individual pages to new URLs, the simpler Redirect directive works well:
Redirect an Entire Folder
Redirect all URLs under an old folder to a new folder:
Custom Error Pages with .htaccess
Beyond redirects, .htaccess also lets you define custom error pages — giving visitors a well-designed experience instead of Apache's raw error output:
A well-crafted 404 page is especially important: when visitors land on a broken link, a good custom 404 page keeps them on your site by offering navigation links, a search bar, or links to popular content. Without it, Apache displays a plain error that most visitors immediately leave.
SEO tip: Your custom 404 page must return an actual HTTP 404 status code — not 200 OK. A "soft 404" (200 status on a not-found page) can confuse Googlebot and cause it to index error pages as real content.
Query String Redirects
Redirect URLs with specific query string parameters — useful when migrating from dynamic URLs to clean static slugs:
Note the trailing ? in the target URL — this tells Apache to strip the original query string from the redirect destination, preventing duplicate parameters from being appended.
Redirect vs RewriteRule: Which to Use?
Both directives handle redirects, but they differ in power and use case:
| Feature | Redirect Directive | RewriteRule |
|---|---|---|
| Complexity | Simple, single URL | Flexible, supports patterns |
| Regex support | No | Full regex support |
| Conditional logic | Not available | RewriteCond conditions |
| Example | Redirect 301 /old /new |
RewriteRule ^old(.*)$ /new$1 [L,R=301] |
| Best for | Single page redirects | HTTPS, www, folder, pattern redirects |
Trailing Slash Redirects
Force trailing slash
Remove trailing slash
Redirect Old Domain to New Domain
When migrating your entire site to a new domain:
Preventing Redirect Loops
Redirect loops (ERR_TOO_MANY_REDIRECTS) are the most common .htaccess mistake. Prevent them by:
- Always adding
RewriteCond %{HTTPS} offbefore HTTPS redirect rules - Using proper host conditions before www/non-www rules
- Ending every RewriteRule with
[L]or[L,R=301] - Testing with 302 first, then switching to 301 once confirmed working
Testing Redirects with curl and Online Tools
After editing .htaccess, test redirects immediately from the command line or use an online checker to view the full redirect chain:
Online tools like httpstatus.io or redirect-checker.org display the full redirect chain with each step's status code — making it easy to spot loops or unnecessary hops. Keep your redirect chain to two hops or fewer (for example, http → https in one hop, not http → http://www → https). Each extra hop adds network latency for every visitor.
Complete .htaccess Template for Most Sites
Tip: All AsiaGB hosting plans support mod_rewrite and AllowOverride All, so .htaccess works at full capacity. Plans start from 500 THB/year with SSD storage, DirectAdmin control panel, and PHP 7.4/8.2/8.3 support.
SSD Hosting with DirectAdmin
Full mod_rewrite support on all plans. Configure .htaccess exactly as you need. Starting at 500 THB/year with 99% Uptime.
View Hosting Plans