Apache 301 Redirect

Apache 301 redirects are SEO-friendly, so configuring 301 redirects via the Apache configuration file is very useful.

Modify the Apache configuration file

For example, my current server’s website domain is www.mytwo.com, and I also want www.myone.com to open www.mytwo.com. The code is as follows:

1
2
3
4
<VirtualHost *:80>
ServerName www.myone.com
RedirectMatch Permanent ^/(.*) http://www.mytwo.com/$1
</VirtualHost>

Another example, an Apache virtual host configuration sample:

1
2
3
4
5
6
<VirtualHost 213.5.65.230:80>
    ServerAdmin [email protected]
    ServerName www.hellokey.com
    ServerAlias hellokey.com
    RedirectMatch Permanent ^/(.*) http://www.hellokeykey.com/$1
</VirtualHost>

This performs a 301 redirect from www.hellokey.com to www.hellokeykey.com

If you want to implement this using .htaccess, simply go to http://www.htaccesseditor.com/sc.shtml to set it up. It’s an online WYSIWYG editor—just paste the generated .htaccess code into your .htaccess file.

Leave a Comment

Your email address will not be published.