How to Redirect Old Domain to New Domain Using htaccess Redirect

I want to move the sub domain to permanently. I can manage all the pages I want to post using WordPress. Changing domain in a bad way is dangerous. Put a page the tell the reader that the site is moved to a new domain is very unfriendly to the user and also the search engine. When I moving my blog two my own domain from HKUST’s iblog, I found most of the readers don’t try to search and find the pages that interest them in the new domain especially when they find the old site by a search engine.

301 Redirect

301 redirect is the most Reader Friendly and Search Engine Friendly method for webpage redirection. The user can get the same page even if they use the old URL. The browser will automatically redirect them to the new address of this page. Of course the URL structure except the domain should keep the same. And the 303 redirect method should preserve the search engine rankings for that particular page. The code “301” is interpreted as “moved permanently”.

.htaccess redirect

The .htaccess method of redirection only works when the server is Apache and the Apache Mod-Rewite module is enabled.

Create a .htaccess file in the root directory of the old domain ( in this example). Then add the below code the .htaccess file:

# BEGIN Redirect
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)$1 [R=301,L]

# END Redirect

With the above code, it will be ensured that all the directories and pages of the old domain ( will get correctly redirected to the new domain. The domain part can be changed to any domain that is needed.

For WordPress, changing the application files is not enough. The domain name has also been stored in the database so the site owner should also change the entries that store the domain name in the database using some tools like phpMyAdmin. There are two entries should be changed in the table wp_options. Just find the two entries whose value is the old domain and change it to the new domain. Then the new domain will be in service now ;)

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.


  1. An alternative way is to use the Redirect if the Apache does not include the rewrite module:

    # Redirect your entire website to
    Redirect 301 /
Leave a Reply

Your email address will not be published. Required fields are marked *