Apache redirect permanent new domain
To redirect a permanent redirect from an old domain to a new domain using Apache, you can use the Redirect
directive in your Apache configuration file.
Here is an example of how you can do this:
<VirtualHost *:80>
ServerName olddomain.com
Redirect permanent / http://newdomain.com/
</VirtualHost>
This will redirect all requests from olddomain.com
to newdomain.com
. The permanent
keyword indicates that this is a permanent redirect, which means that search engines and other crawlers will update their indexes to point to the new domain.
You can also specify a specific URL to redirect, for example:
<VirtualHost *:80>
ServerName olddomain.com
Redirect permanent /old-path http://newdomain.com/new-path
</VirtualHost>
This will redirect all requests from olddomain.com/old-path
to newdomain.com/new-path
.
You can also use the RedirectMatch
directive to redirect based on a regular expression:
<VirtualHost *:80>
ServerName olddomain.com
RedirectMatch permanent ^/(.*)$ http://newdomain.com/$1
</VirtualHost>
This will redirect all requests from olddomain.com
to newdomain.com
, preserving the original URL path.
Make sure to update your Apache configuration file and restart the Apache service for the changes to take effect.
Note: You can also use the mod_rewrite
module to achieve the same result, but the Redirect
directive is a more straightforward and easy-to-use solution.