Edward
Edward

Reputation: 15

.htaccess code to redirect old blog urls to new blog urls on a new domain

I'm trying to redirect an old wordpress blog to a new posterous blog using an htaccess file and I am using the code below; the problem is that I can't get the old individual blog posts to redirect to the new ones - they have the same name structure on the new domain name (eg: olddomain.com/post-1 is now newdomain.com/post-1), but if I type in one of the old post urls I get a 500 error. My home page, category and index pages are all redirecting fine as well as the 301 redirects at the bottom for the old wordpress page urls. What am I doing wrong?

Options +FollowSymlinks  

<IfModule mod_rewrite.c>  
RewriteEngine On  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^category/(.*)$ http://newdomain.com/tag/$1 [R=301,L]  
RewriteRule ^page/(.*)$ http://newdomain.com/\?page=$1 [R=301,L]  
RewriteRule . /index.php [L]  
RewriteCond %{HTTP_HOST} ^www.olddomain.com [nc,or]  
RewriteCond %{HTTP_HOST} ^olddomain.com [nc,or]  
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,nc]  
</IfModule>  

redirect 301 /page-1 http://newdomain.com/page-1  
redirect 301 /page-2 http://newdomain.com/page-2  
redirect 301 /page-3 http://newdomain.com/page-3  

Upvotes: 0

Views: 2760

Answers (3)

Pikai
Pikai

Reputation: 1

you should just write the below code into your .htaccess file. (This will automatically redirect all your old post URLs from your old domain to the exact new domain urls):

RewriteEngine on
RewriteBase /
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]

Upvotes: 0

Edward
Edward

Reputation: 15

I got it to work by replacing old individual page redirect code:
redirect 301 /page-1 http:// newdomain .com/page-1

with new rewrite rules:
RewriteRule ^page-1/?$ http:// newdomain .com/pages/page-1 [R=301,L]

and placing the page these rules above the directory and site wide rules. Note: you need to remove the spaces from the newdomain url which I had to add as new users on the site can't add urls to their posts.

Upvotes: 0

bvandrunen
bvandrunen

Reputation: 443

You need to do:

RedirectPermanent /old_page http//www.newawesomesite.com/old_page

Upvotes: 0

Related Questions