Forum Moderators: phranque
Right now I'm using .htaccess to redirect 301 many of my main pages to the new site.
ErrorDocument 404 [newsite.com...]
redirect 301 /blog/index.html [newsite.com...]
redirect 301 /index.html [newsite.com...]
redirect 301 /onepage.html [newsite.com...]
redirect 301 /anotherpage.html [newsite.com...]
Now this is working for all of these,but I have hundreds of archives at this location
[oldsite.org...]
They are all in various formats also. Here are some examples...
005168just_checking_to_see_if.html
002348another_example.html
2003_06.html
2005_01.html
yet_another_example.html
and so on and so on. There are about 1000 or more.
My new site is set up a little differently without using a /blog directory for the weblog. Its just in my home directory now. and the archives are imported into a directory like this
[newsite.com...]
No like I said. So far the main pages are all redirected to the new site with .htaccess but I need all my archives that are indexed with the search engines to be sent to my main page or matched with my archives directory.
I saw one post with this mod rewrite some one used and I tried to edit it with no luck.
ErrorDocument 404 [newsite.com...]
RewriteEngine on
# Rewrite forum subdomain to /home/www/mysite.com/forum subdirectory
rewritecond %{http_host} ^archives\.newsite\.com
RewriteRule (.*) /home/www/newsite.com/archives/$1 [L]
#
# Redirect all other non-blank non-www domains to www domain
rewritecond %{http_host} .
rewritecond %{http_host}!^(www¦archives)\.newsite\.com
RewriteRule (.*) [newsite.com...] [R=301,L]
I realize that its for a subdomain and that is not what I have, but I'm clueless when it comes to Rewrite. If someone could help me out on this I would be greatful.
So what I need would be all my archives and main pages sent to www.newsite.com or matched up with my newly indexed pages on my new site (www.newsite.com/archives). How would that be done? Can you use both redirect 301 like I already have and mod rewrite or just one or the other?
Hope I explained that clearly enough. If not just let me know any other info you might need to figure this out.
Thanks
Personally I prefer mod_rewrite... actually it's the only thing I use. The added flexibility (especially in the case of large numbers of pages) is often essential.
I think what you are asking is if you can redirect traffic from old-site.com to new-site.com and remove the directory /blog/ along the way?
If this is correct you can use a very simple regular expression and mod_rewrite.
To move your files from old-site.com/blog/ to new-site.com/ (as long as the file names are the same, just at different location) you could use something like this:
RewriteEngine on
RewriteRule ^blog/(.*)$ http://www.new-site.com/$1 [R=301,L]
(To go to new-site.com/archives/stuff, change the right side of the rule to http:new-site.com/archives/$1)
If you use this in the .htaccess of the root directory on old-site.com, you will redirect everyfile within the directory /blog/ to new-site.com/ with exactly the-same-file-name.html.
Here's how it works:
Line 1 turns on the rewrite engine.
^ starts the line.
blog/ matches the pattern on the way to the directory/file you want to move.
(.*) matches 0 or more of any character () indicates 'store in a variable' '.*' does the actual matching.
http designates an external rewrite by default.
$1 means 'put the stored information here'.
R=301 indicates a permanent redirect.
L means 'stop precessing now'.
Yes, you can use both types of redirection as long as both modules are installed.
Hope this helps.
Justin
And does this go in my .htaccess file in the home/root directory?
I'll give it a shot in the morning after I've gotten some rest. Its been a long day.
Thanks again.
ErrorDocument 404 [new-site.com...]
RewriteEngine on
RewriteRule ^blog/(.*)$ [new-site.com...] [R=301,L]
redirect 301 /index.html [new-site.com...]
redirect 301 /page-1.html [new-site.com...]
redirect 301 /page-2.html [new-site.com...]
Now everything in my root directory is being redirected but only the index.html file in /blog is getting redirected with the new RewriteRule. All other files in the /archives give me a 404 Error.
I added "archives" to the RewriteRule below
RewriteEngine on
RewriteRule ^blog/(.*)$ [new-site.com...] [R=301,L]
but that started giving me a 403 error with the index.html in /blog directory. I also tried putting "archives" after the "^blog/archives(.*)" just in case. No 403 or 404 error but the page loaded normally with no redirect at all.
I just found your tutorial on the site and I'll read over that but if anyone has any suggestions that would be great also because I've spent about an hour trying different combinations.
Something I noticed about my "new-site/archives" is that there are a lot of sub directories now. In the "old-site/archives" it was just the files themselves. But with the new site it indexed everything differently. LIke this:
new-site/archives/year/month/files.html
new-site/archives/category/index.html
So I guess there really isn't a match being made. If I can just get my archives to redirect to my "new-site/index.html" that would be a plus but I can't seem to get that to work.
Thanks
The biggest problem with asking for help on this is... we don't know the exact structure of your site and unfortunately mod_rewrite is an exact science.
If I understand, you have two directories that you would like to redirect. 1. /blog/ 2. /archives/. You are right the sub-dir's opposed to file names is an issue, so going to either the index, or the /blog/index sees like a good option. To do this you would need a second rule.
RewriteEngine on
RewriteRule ^blog/(.*)$ http://www.new-site.com/$1 [R=301,L]
RewriteRule ^archives/.*$ http://www.new-site.com/where-ever-you-want-it-to-go.html [R=301,L]
Please notice the differences in the second rule.
1. .* does not store the information in a variable, because we are redirecting all the pages to one.
2. the right side of the rule does not contain the $1 to retrieve the variable, because we are going to code a specific page in to the location.
I am not sure of your exact structure, so there is at least one more possibility.
If your old-site URL is blog/archives/, you would need to add blog to the beginning of the second rule and reverse the order of the rules, so the one with blog/archives/ is processed first.
Hope this helps.
Justin
BTW Looks like you got close... Thank you for trying and posting what you tried... I really like being able to help people who are making an effort to figure things out and make them work.
RedirectMatch (.*)\.html$ [new-site.com...]
Now everything that has anything to do with my old archives is being directed to my new sites index.html. Seems to work for me for now. No 404 errors at least. There are always better ways to do this I'm sure. If anyone knows of a better way to get this result just let me know.
Thanks for all of your help on the forum.
(guess we posted at almost the same time)lol!
ErrorDocument 404 [new-site.com...]
RewriteEngine on
RewriteRule ^blog/archives/.*$ [new-site.com...] [R=301,L]
RewriteRule ^blog/(.*)$ [new-site.com...] [R=301,L]
redirect 301 /index.html [new-site.com...]
redirect 301 /page-1.html [new-site.com...]
redirect 301 /page-2.html [new-site.com...]
Now everything is directed to my main page and it has a search someone can use from there to find what they were looking for.
I'm still not clear why the one RewriteRule had to be switched in front of the other one to be processed first. ?