When migrating from one blogging software program to another, or even when changing domains, the WordPress administrator may need to redirect old links to the new site.
If your site server uses Apache, the ability to control the redirection of your site's user's page request is controlled by instructions within the .htaccess file. This file must be in the same directory on your site as your root index.php file is, no matter where your WordPress files are stored.
The .htaccess file is used by WordPress to store permalink instructions and it may also be used to store redirection instructions if you are changing page addresses.
To begin to play your redirects, you must understand how WordPress' link structure works, and how it relates or doesn't relate to your old file path and link structure.
WordPress uses two link "styles" for it's documents. One is SOMETHING SOMETHING that uses the ID numbers for the posts, Pages, and categories based upon the index.php address, such as:
http://example.com/index.php?p=42 http://example.com/index.php?cat=12 http://example.com/index.php?page_id=3
WordPress also uses permalinks for more "readable" link structures:
http://example.com/stories-about-wordpress/ http://example.com/category/wordpress/ http://example.com/pages/about/
Whether you are using the first or second link structure within WordPress, when creating your site and page redirection instructions in your .htaccess file, you can use the first example since it will work whether or not you are using permalinks, and will maintain their function even if you change your permalink structure.
If you have installed WordPress and are moving from a HTML site to WordPress, simple redirects can work to point your users in a new direction.
For example, on your static site, your "About" page was at example.com/about.html. Now, using WordPress Pages, it is located at example.com/index.php?page_id=3. For visitors visiting your site from the old address, you want to redirect them automatically to your new page location.
In the .htaccess file, using a text editor, add the following:
RedirectPermanent /about.html http://example.com/index.php?page_id=3
Anyone visiting that age by typing or clicking a link to the old address will be redirected to the new Page. You can redirect all your old page addresses to the new WordPress addresses this way, but it could prove tedious. There are shorter ways to get to the same path.
This is where something about making some shortcuts in redirections and rewrites needs to go.
To redirect everything except /cgi-bin
to the directory /wp
, which might hold WordPress, use the below. Notice /wp
is not being redirected to itself.
RewriteEngine on RewriteCond REQUEST_URI !^/*(cgi-bin|wp) RewriteRule (.*) http://www.leegoddard.net/wp/$1 [R=301,L]
When changing from one blogging software program to WordPress, mod_rewrite and .htaccess will help you to maintain your links from your old site to your new one.
Begin the process by analyzing the old link file path with WordPress'. For example, Typepad features this structure:
Typepad names permalinks like this:
http://example.com/2004/04/title_of_post.html
WordPress uses this format:
http://example.com/2004/04/title-of-post/
Using mod_rewrite you can set your .htaccess file to redirect the incoming links from the old address to the new by:
RewriteRule ^([0-9]{4}/[0-9]{1,2}/.*)\.html $1/ [PT]
During the migration process, links to images within your posts may also need redirection. There are several ways to do this.
example.com/wp-images/
example.com/shared/images/
RewriteCond %{QUERY_STRING} ^/([^.]+)(\.htm) [OR] RewriteCond %{QUERY_STRING} ^/([^.]+)(\.jpg) RewriteRule ^\.shared/image.\html$ /%1%2 [R=301,L]
Images associated with thumbnails may also have problems of their own. The above three methods may also help to repair those links, too. For example, Typepad may add the filepath .../.shared/image.html?/... to some, but not all thumbnails. Using phpMyAdmin UPDATE SQL, removing /.shared/image.html?/ from the file path may solve the problem, allowing the linked full-size images to display properly.