Forum Moderators: phranque

Message Too Old, No Replies

Catch All Redirect and Specific Page Redirects

How do I set up a catch-all redirect in addition to specific page redirects

         

SEOHolicc

11:17 pm on Jun 16, 2009 (gmt 0)

10+ Year Member



Ok, this one has me completely confused.

My client has an old site which they decided to expand into a new site.

I want to redirect all the articles of the old site to the new site, but then set up a catch-all 301 redirect to go to a subdomain on the new site.

Sorta like this;

DenverOldSite.com/article1.html should go to NewSite.com/article1.html

but anything outside of the articles should be caught and go to the home page of Denver.NewSite.com.

So far I have this in the .htaccess

## CATCH-ALL REDIRECT##
RewriteCond %{HTTP_HOST} ^(oldsite¦www.oldsite) [NC]
RewriteRule ^(.*)$ http://denver.newsite.com/$1 [R=301,L]

redirect 301 /article1.html http://www.newsite.com/article1.html

So the catch-all redirect is working, but the specific page redirect does not go to the new site, but automatically goes to the subdomain article1.html page.

Is it possible to redirect like this?

I appreciate any advice anyone can give me on this.

[edited by: jdMorgan at 12:05 am (utc) on June 17, 2009]
[edit reason] de-linked [/edit]

jdMorgan

12:05 am on Jun 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't mix mod_rewrite (RewriteRule) with mod_alias (Redirect) if you want to control the order or priority of the directives. Use mod_rewrite for both types of redirect, and put the most-specific rules first. In this case that would mean putting the rewriterules for the articles first.

Jim

SEOHolicc

2:16 pm on Jun 17, 2009 (gmt 0)

10+ Year Member



Worked perfectly. You're awesome!

Thanks for your help Jim

[edited by: SEOHolicc at 2:16 pm (utc) on June 17, 2009]

g1smd

12:46 am on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Let's see the code, in case there are other things that can be optimised.

SEOHolicc

2:30 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



Sure thing. This is what it looks like now.

Options +FollowSymlinks

RewriteEngine On

## SEND ARTICLES BACK TO ROOT DOMAIN ##
RewriteRule ^articles/(.*)$ http://www.newsite.com/articles/$1 [R=301,L]
RewriteRule ^/articles/article1.html(.*)$ http://www.newsite.com/article/article1.html$1 [R=301,L]

## CATCH-ALL REDIRECT ##
RewriteCond %{HTTP_HOST} ^(oldsiteaustin¦www.oldsiteaustin) [NC]
RewriteRule ^(.*)$ http://austin.newsite.com/$1 [R=301,L]

[edited by: jdMorgan at 5:52 pm (utc) on June 18, 2009]
[edit reason] De-linked. [/edit]

jdMorgan

5:08 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest:

# Redirect specific article requests (this is only needed
# when the new page's URL-path is not the same as the old)
RewriteRule [b]^art[/b]icles/[i]our-tickle[/i]1.html(.*)$ http://www.newsite.com/article/article1.html$1 [R=301,L]
#
# Redirect all article URL requests to new domain,
# retaining originally-requested article URL-path
RewriteRule ^articles/(.*)$ http://www.newsite.com/articles/$1 [R=301,L]
#
# Redirect non-canonical domain (and old non-article) requests to a subdomain of
# the (new) canonical domain, retaining originally-requested article URL-path
RewriteCond %{HTTP_HOST} [b]^(www\.)?oldsiteaustin\.com[/b] [NC]
RewriteRule ^(.*)$ http://austin.newsite.com/$1 [R=301,L]

Jim

SEOHolicc

5:34 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



Does changing this make them faster or less time-consuming for the server to process?

jdMorgan

5:50 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In general, shorter is better.

I'm not sure what your now-first rule is for actually, since the second rule will cover all cases where the URL-paths (loosely, the "page file names") on the old and new domains are the same. And also, as you had posted it above, it would have never been invoked, since URL-paths seen by RewriteRule in .htaccess do not start with a slash. I corrected that above, but if you don't need the first rule, get rid of it -- That wiil certainly speed things up...

I may have missed your specific question here... Not sure.

Jim

SEOHolicc

7:38 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



Ahh, I see. Yes, that answered my question. Thanks.