mod rewrite - Apache > How to redirect the home page and others urls separately? -
i'm dealing website overhaul in special configuration : 2 websites hosted on 2 different servers new domain name new one. new domain online, have redirect old domain old server running on apache 2.2.16.
thus, have redirect old domain home page new domain home page :
http://www.oldwebsite.com > http://www.newwebsite.com
and @ same time have redirect old urls separately 1 one (for seo purpose because new domain urls optimized) :
http://www.oldwebsite.com/page1/ > http://www.newwebsite.com/newpage1/ http://www.oldwebsite.com/page2/ > http://www.newwebsite.com/newpage2/ http://www.oldwebsite.com/page3/ > http://www.newwebsite.com/newpage3/ http://www.oldwebsite.com/directory1/ > http://www.newwebsite.com/newdirectory1/ http://www.oldwebsite.com/directory2/ > http://www.newwebsite.com/newdirectory2/ http://www.oldwebsite.com/directory3/ > http://www.newwebsite.com/newdirectory3/ etc.
therefore, put in htaccess file on old server these rules :
rewriterule ^/?$ http://www.newwebsite.com/ [r=301,l] rewriterule ^page1$ http://www.newwebsite.com/newpage1/? [r=301,l] rewriterule ^page2$ http://www.newwebsite.com/newpage1/? [r=301,l] rewriterule ^directory1(.*)$ http://www.newwebsite.com/newdirectory1/? [r=301,l] rewriterule ^directory2(.*)$ http://www.newwebsite.com/newdirectory2/? [r=301,l] rewriterule ^directory3(.*)$ http://www.newwebsite.com/newdirectory3/? [r=301,l] etc.
note : added "?" @ end of new urls prevent transfer of old parameters in order avoid duplicate content. heard way on former apache versions.
when did so, home page redirected , others rules not followed. changed order of rules getting first rule end, :
rewriterule ^page1$ http://www.newwebsite.com/newpage1/? [r=301,l] rewriterule ^page2$ http://www.newwebsite.com/newpage1/? [r=301,l] rewriterule ^directory1(.*)$ http://www.newwebsite.com/newdirectory1/? [r=301,l] rewriterule ^directory2(.*)$ http://www.newwebsite.com/newdirectory2/? [r=301,l] rewriterule ^directory3(.*)$ http://www.newwebsite.com/newdirectory3/? [r=301,l] etc. rewriterule ^/?$ http://www.newwebsite.com/ [r=301,l]
now result, home page still redirected rest of urls respond 500 error status.
do have idea of what's wrong in file ? many thanks.
found article may solve prob
.htaccess 301 redirect path , child-paths
use these lines of code:
rewriterule ^page1$ http://www.newdomain.com/ [r=301,l,qsa] rewriterule ^page1/(.*) http://www.newdomain.com/$1 [r=301,l,qsa]
Comments
Post a Comment