Updated: 30 November 2026 · Applies to: Apache 2.4 (tested 2.4.69), nginx 1.30, cPanel 82 and later, Virtualmin, Sentora
To redirect a whole domain permanently, send a 301 response that points every old address to the same path on the new domain. On Apache or a cPanel account that is two lines in the old domain's .htaccess file; on nginx it is one return 301 line. A 301 tells browsers and search engines the move is permanent, so they update bookmarks and pass the old pages' ranking to the new ones.
The examples below move example.com to https://www.example.org. Replace both with your own domains.
Option 1: the cPanel Redirects tool
According to cPanel's documentation, the tool is in the Domains section of cPanel:
- Open Domains › Redirects.
- Set Type to Permanent (301).
- Choose the old domain in the domain menu (or All Public Domains).
- Leave the path box as
/to redirect the whole domain. - In Redirects to, enter the full new address, including
https://. - Pick Redirect with or without www. so both forms of the old domain move.
- Tick Wild Card Redirect if every page should land on the same path at the new domain, then click Add.
cPanel writes the rule at the bottom of the domain's .htaccess file. Applications such as WordPress add their own rules above it, so if the redirect does not work, use Option 2 and put your rule at the top. See also How to setup domain redirects in cPanel?
Option 2: rules in .htaccess (Apache and cPanel)
Open the old domain's document root (for example with File Manager, see What Is .htaccess and How to Edit It in cPanel) and add these lines at the very top of .htaccess. They keep the path and the query string, so /blog/post.html?id=7 lands on the same page at the new domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]
If the old domain has its own folder and you only need a plain move, the shorter Redirect line does the same job. It also keeps paths and query strings:
Redirect 301 / https://www.example.org/
On the new domain, this rule sends HTTP visitors and the non-www name to one address, https://www.example.org, in a single hop:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^example\.org$ [NC]
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]
For HTTPS-only rules and the common loops, see How to Redirect HTTP to HTTPS with .htaccess (301 Redirect). For more on rewrite syntax, see How to use Apache mod_rewrite.
Option 3: nginx server block
nginx does not read .htaccess. On your own VPS or dedicated server, give the old domain its own server block that returns a 301:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.org$request_uri;
}
$request_uri carries the path and query string. If the old domain also has an SSL certificate, add the same return 301 line to its listen 443 ssl block. Test the configuration, then reload:
nginx -t
systemctl reload nginx
For the www form of a single domain, see How to redirect Nginx non-www to www domain over SSL?
Option 4: Virtualmin
According to Virtualmin's documentation:
- Select the old domain in the menu on the left.
- Open Web Configuration › Website Redirects and click Add a new website redirect.
- Set Source URL path to
/and Destination to URL at other website with the new address. - Set HTTP redirect type to 301 and Redirect sub-directories to to Same sub-directory under destination URL.
- Under Enable redirect for, tick both SSL and non-SSL, then click Create.
From the command line the same redirect is (without --code 301 Virtualmin uses 302):
virtualmin create-redirect --domain example.com --path / --redirect https://www.example.org/ --code 301
A note for Sentora and ZPanel users
Sentora (a fork of ZPanel) is an old panel that is no longer a good choice for new servers; see Sentora Control Panel in 2026: Project Status and Supported Alternatives. If you still run it, the .htaccess rules in Option 2 work on its Apache. As admin you can also add Redirect 301 / https://www.example.org/ to the domain's virtual host under Admin › Module Admin › Apache Config and wait for the configuration to rebuild.
Test the redirect
Ask for the headers only with curl -I. A working rule answers 301 with a Location line that points to the new address and keeps the path:
curl -I "http://example.com/blog/post.html?id=7"
Output from a test container (the Date line is left out):
HTTP/1.1 301 Moved Permanently Server: Apache/2.4.69 (Debian) Location: https://www.example.org/blog/post.html?id=7 Content-Type: text/html; charset=iso-8859-1
If you see 302 Found, the rule is temporary: change it to 301. If you see the same Location again and again, two rules are sending visitors back and forth. Browsers cache 301 responses, so test with curl or a private window after each change.
Official documentation: cPanel Redirects, Apache mod_alias Redirect, nginx return.