Redirect old domain to new domain htaccess
To redirect an old domain to a new domain using .htaccess
file, you can use the following code:
Redirect 301 /old-domain.com http://new-domain.com
This will redirect all requests from old-domain.com
to new-domain.com
.
If you want to redirect specific pages or directories, you can use the following format:
Redirect 301 /old-domain.com/path/to/page http://new-domain.com/new-path/to/page
This will redirect requests from old-domain.com/path/to/page
to new-domain.com/new-path/to/page
.
You can also use the RedirectMatch
directive to redirect based on a regular expression:
RedirectMatch 301 ^/old-domain.com/(.*)$ http://new-domain.com/$1
This will redirect all requests from old-domain.com
to new-domain.com
, preserving the path and query string.
Note:
301
is the HTTP status code for a permanent redirect. You can use302
for a temporary redirect if needed.- Make sure to update the
old-domain.com
andnew-domain.com
URLs to match your actual domain names. - If you have multiple domains to redirect, you can add multiple
Redirect
orRedirectMatch
directives to your.htaccess
file.
Here is an example of a complete .htaccess
file that redirects multiple domains:
Redirect 301 /old-domain1.com http://new-domain1.com
Redirect 301 /old-domain2.com http://new-domain2.com
RedirectMatch 301 ^/old-domain3.com/(.*)$ http://new-domain3.com/$1
Remember to update the .htaccess
file on your server and test the redirects to ensure they are working correctly.