homepage Welcome to WebmasterWorld Guest from 54.211.34.105
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
redirecting a large site with .htaccess
looking for a good 301 redirect strategy
bill

WebmasterWorld Administrator bill us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 444 posted 7:36 am on Feb 6, 2002 (gmt 0)

I need a bit of advice/help.

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?

 

gethan

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 444 posted 10:59 am on Feb 6, 2002 (gmt 0)

Hi Bill

.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 ;)

sugarkane

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 444 posted 3:44 pm on Feb 6, 2002 (gmt 0)

You could also do it with mod_alias, which has less overhead than mod_rewrite. In your .htaccess on your original site:

RedirectMatch 301 /english/(.*\.html)$ htt*://www.newsite.com/$1

bill

WebmasterWorld Administrator bill us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 444 posted 2:04 am on Feb 7, 2002 (gmt 0)

Wow. Thanks for the help. This place never ceases to amaze me.

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?

deltab

10+ Year Member



 
Msg#: 444 posted 5:41 am on Feb 7, 2002 (gmt 0)

Bill: You got it right the first time - a simple RedirectPermanent will do what you want.

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)

bill

WebmasterWorld Administrator bill us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 444 posted 6:24 am on Feb 7, 2002 (gmt 0)

deltab thanks for the help and welcome to WebmasterWorld.

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

With IE6.02 your redirect isn't working...at least on my machine. It worked with Opera 6, Mozilla 0.9.3, and NN4.7...just not my IE. In IE6.02 I'm getting http://olddomain.com/anything/you/like/here/ --> 404 and the redirect is not happening (I stay on the http*//olddomain.com domain)

Your Apache conf file method doesn't involve .htaccess at all?

(edited by: DaveAtIFG at 7:42 pm (utc) on Feb. 7, 2002)

sugarkane

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 444 posted 10:02 am on Feb 7, 2002 (gmt 0)

deltab - yep, that'd work if you wanted to redirect the whole site to a mirror, but in bill's case the match rule is needed as (if I read it right) different parts of the site will be redirected to different domains, so a bit more control is necessary.

> (.*\.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.

gethan

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 444 posted 10:22 am on Feb 7, 2002 (gmt 0)

Bill, I'd go with sugarkane's method for this one - I've been mod_rewrite mad for the last couple of months and have overlooked simpler options.

If you do use the mod_rewrite method above - note I made a mistake and the + should be a *.

bill

WebmasterWorld Administrator bill us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 444 posted 12:21 am on Feb 8, 2002 (gmt 0)

If I use sugarkane's method I would place the .htaccess file in my current root directory, and then use it like this?

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

sugarkane

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 444 posted 9:39 am on Feb 8, 2002 (gmt 0)

Yup, that's it exactly bill.

bill

WebmasterWorld Administrator bill us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 444 posted 11:58 pm on Feb 8, 2002 (gmt 0)

Cool. This doesn't look all that hard now ;)

sugarkane mentioned that I could use the following to redirect everything
[color=blue]RedirectMatch 301 /english/(.*)$ htt*://www.newsite.com/$1[/color]Would it be possible to modify this to just redirect for .html and .pdf files?

Gorufu

10+ Year Member



 
Msg#: 444 posted 1:09 am on Feb 9, 2002 (gmt 0)

G'day Bill,

> 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.

bill

WebmasterWorld Administrator bill us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 444 posted 4:12 am on Feb 9, 2002 (gmt 0)

Thanks Gorufu. I think I'm ready to go out and wreak havoc on this company's sites. I have just enough knowledge to do some damage...of course I'll be back if I mess anything up ;)

Thanks everyone

wilderness

WebmasterWorld Senior Member wilderness us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 444 posted 4:00 pm on Feb 10, 2002 (gmt 0)

<RedirectMatch 301 /english/(.*\.(html¦pdf))$ htt*://www.newsite.com/$1 >

Is it possible to configure this to some sort of NULL to specify a 410 code?

Thanks in advance

deltab

10+ Year Member



 
Msg#: 444 posted 5:35 pm on Feb 10, 2002 (gmt 0)

wilderness: Yes. According to the docs [httpd.apache.org] the following should work:

Redirect gone /old/path/prefix

I've never used that though.

wilderness

WebmasterWorld Senior Member wilderness us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 444 posted 5:59 pm on Feb 10, 2002 (gmt 0)

I have some pages that have been <gone> for nearly two years which still get requests from the search engines.
Which results in a crazy circle between SE's and visitors.

I've had replacemt pages which are nearly blank specifying 410 that the page has been permanently removed and yet access continues.

Many thanks

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved