Forum Moderators: phranque
A company I work with is splitting its website into several different smaller websites that will be hosted under different domains and at different hosting companies. They don't want to lose any people who have bookmarked the site, nor do they want to lose any SE rankings. The current website is hosted on an in-house server (*nix, Apache) but has outgrown its box.
Even though I have no experience with this, during a recent meeting I mentioned the possibility of using an .htaccess to generate a 301 RedirectPermanent as I've read so much about here at WebmasterWorld. I assumed that someone would know what I was talking about, but it turns out nobody had thought of this, and now I'm the website relocation guru. next time I'm keeping my mouth shut ;)
I saw a couple of examples of how to do redirects in the thread entitled How to do a 301 permanent redirect and what are the effects. [webmasterworld.com] The redirectPermanent option looked a lot more understandable for someone as code-challenged as myself. I just couldn't wrap my head around the mod_rewrite. However I need a bit more clarification...
Some sections of the site will be moved with exactly the same structure, only the domain name will change. So if I were going to try and move the following:
htt*://www.oldsite.co.jp/english/ -->
htt*://www.newsite.com/
I would drop an .htaccess file under the root htt*://www.oldsite.co.jp/ like so?
redirectPermanent htt*://www.oldsite.co.jp/english/ htt*://www.newsite.com/
Would that carte blanche redirect any requests under the /english/ folder? Or is it necessary to map each page directly?
.htaccess in your english dir.
[perl]
rewriteEngine on
rewriteRule ^/english/(.+) [newdomain.com...] [L,R=301]
or
rewriteEngine on
rewriteBase /english/
rewriteRule ^(.+) [newdomain.com...] [L,R=301]
[/perl]
Will do what your looking for.
The caveat with using the method you list, is that bookmarks and links (non-homepage) would all be redirected to the new homepage. mod_rewrite saves you have to do this for every page.
I recently moved my entire site from .com to .co.uk - I'll let you know what happens to rankings as a result.... so far the spiders have all gone to the right places - will my PR follow through ;)
So the redirectPermanent method I outlined above now looks much more cumbersome...I'd have to map each page to its new location if I didn't want to simply redirect people to the new home page. Thanks for clearing that up for me.
Please confirm if I'm understanding this correctly. If I use the mod_rewrite or mod_alias methods above, any page under the relative subdirectory will be redirected to the exact same page only on the new domain.
htt*://www.oldsite.co.jp/english/a.html --> htt*://www.newsite.com/a.html
htt*://www.oldsite.co.jp/english/a/b.html --> htt*://www.newsite.com/a/b.html
htt*://www.oldsite.co.jp/english/a/b/c.html --> htt*://www.newsite.com/a/b/c.html
sugarkane I hadn't really looked at this mod_alias option before. In your example I see (.*\.html), would this need to be modified for files like .htm, or PDFs or others?
See the Apache docs on mod_alias [httpd.apache.org] for details and an example. (Note that the Redirect directives are provided by mod_alias.)
The suggestions by others will also work, but they're overpowered for this particular need.
A demonstration: one of my customers expanded his Scream Machines site to include other roller coaster games, and changed the name to suit. I put this into his Apache conf file:
<VirtualHost 123.456.789.123>
ServerName www.olddomain.com
ServerAlias olddomain.com
Redirect permanent / http://newdomain.net/
</VirtualHost>
Now if you request <http://olddomain.com/anything/you/like/here/>, you'll be redirected:
GET http://olddomain.com/anything/you/like/here/ --> 301 Moved Permanently
GET http://newdomain.net/anything/you/like/here/ --> 404 Not Found
Notice how only a prefix of the requested URI was changed in the redirection: all the old URIs are automatically mapped to the corresponding new ones. It really is that simple - no RedirectMatch or RewriteRule needed. (If however he wanted
the redirect to be to the new front page, I'd use RedirectMatch seeother ^/(.+)$ http://newdomain.net/. (303 See Other [w3.org] because the front page wasn't the one asked for.))
Hope this clarifies things.
(edited by: DaveAtIFG at 7:41 pm (utc) on Feb. 7, 2002)
I guess my quandary now is which of these solutions is simplest and most universally applicable? The reason I say this is that although everything is hosted in-house now, very shortly even the root domain is going off to it's own server somewhere...and I'm only assuming they'll still be using Apache.
deltab, I got some odd behavior with the sample you posted
GET http://olddomain.com/anything/you/like/here/ --> 301 Moved Permanently
GET http://newdomain.net/anything/you/like/here/ --> 404 Not Found
Your Apache conf file method doesn't involve .htaccess at all?
(edited by: DaveAtIFG at 7:42 pm (utc) on Feb. 7, 2002)
> (.*\.html), would this need to be modified for files like .htm
Yes - you can modify it to whatever filetype you want. You could even just use /english/(.*)$ to match absolutely anything below the 'english' directory.
[color=blue]RedirectMatch 301 /english/(.*\.html)$ htt*://www.newsite.com/$1
RedirectMatch 301 /chinese/(.*\.html)$ htt*://www.newsite.cn/$1
RedirectMatch 301 /french/(.*\.html)$ htt*://www.newsite.fr/$1 [/color]
> Would it be possible to modify this to just redirect for .html and .pdf files?
the following should do the trick
RedirectMatch 301 /english/(.*\.(html¦pdf))$ htt*://www.newsite.com/$1
Please note: ¦ is the pipe symbol. If you copy and paste the code the pipe symbol will need to be hand edited.
Redirect gone /old/path/prefix
I've had replacemt pages which are nearly blank specifying 410 that the page has been permanently removed and yet access continues.
Many thanks