开发者

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

开发者 https://www.devze.com 2023-01-18 16:07 出处:网络
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 t

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 [开发者_JAVA百科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  


You need to do:

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


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.


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消