homepage Welcome to WebmasterWorld Guest from 54.166.122.65
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirect complete site to root of new domain
Kirsten659



 
Msg#: 4651472 posted 5:45 pm on Mar 5, 2014 (gmt 0)

Hello,

I have a website with about 200 indexed pages.
I would like to redirect all those pages to the root of a new domain (a 1 page website).
If possible I also would like to permanently redirect the page rank (and other SEO value) of all those pages to the root of the new domain.

After some research on Google I think this is the way to do this:

Redirect 301 / http://www.newdomain.com/

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]



Is this the correct way to do this or are there better ways to do this?

Thanks,
Kirsten

 

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4651472 posted 9:23 pm on Mar 5, 2014 (gmt 0)

Kirsten, I hope you appreciate that the immediate reaction of everyone reading the thread title was "Nooooo!"

I think this is the way to do this

It's wrong in so many ways that I can't even list them. That's wrong as in incorrect, not wrong as in immoral.

:: wandering off for a quick chorus of The Log Driver's Waltz [nfb.ca] to recoup my strength before answering the question ::

Kirsten659



 
Msg#: 4651472 posted 9:52 pm on Mar 5, 2014 (gmt 0)

Thanks for your reply Luucy. But honestly I don't see what's wrong with my question if you know "our situation".

The situation is that our old website was all about a business unit that has recently been acquired by another company. We continue with another business unit (same sector/business) but with another domain and just a 1 page website.
So only 1 page still needs to be indexed (the homepage of the new domain) and we would like to permanently redirect all the pages of the old website to that page.

I really would appreciate it if someone could give me the correct code for the htaccess.

Thanks,
Kirsten

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4651472 posted 10:16 pm on Mar 5, 2014 (gmt 0)

RewriteEngine On
RewriteRule .? http://www.example.com/ [R=301,L]

but don't rely on any PageRank or linking credit for this.

In general, dumping visitors at the root page of a different website is an appaling user experience and one that you should fervently seek to avoid.

Kirsten659



 
Msg#: 4651472 posted 11:27 pm on Mar 5, 2014 (gmt 0)

Thanks for your reply.
I understand that it can look as a bad user experience but what's the alternative? The first site is already offline (has become a parked domain of the new domain). If someone clicks now on an indexed page of that site, they get a 404 error.
With the new method, they arrive on our new website and see there that it's our new website (that's offering about the same services)... This is better than a 404 error, isn't it?
I think this offers the best user experience given the circumstances.

I have 2 more questions:
- I suppose with this htaccess in a few days all indexed pages of the old site will disappear from Google and only that 1 page of the new website will be indexed?
- You say "don't rely on any PageRank or linking credit for this". Isn't there a way then to move some of the PageRank or linking credit from the old site to the new site?

Thanks,
Kirsten

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4651472 posted 11:46 pm on Mar 5, 2014 (gmt 0)

Edit:
The following was composed before I saw your reply.


OK, I'm back.

#1
Redirect 301 / http://www.example.com/

We're in htaccess, right? Never combine mod_alias rules ("Redirect" by that name) with mod_rewrite rules. Once you've got anything using mod_rewrite, convert any existing mod_alias rules to use mod_rewrite syntax and make sure they're in the right order. Here you can simply dump the mod_alias (Redirect...) rule, since it doesn't do what you want.

Perversely, it does do what would make for a better user experience: it redirects each request, page for page, to the same page on the new domain. But this is no good if you haven't got those new pages.

#2
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]

The -f test is a server-greedy condition that should be used only as a last resort. Now, it kinda looks as if this second rule is intended to go in the new domain's htaccess, while the first one was meant for the old domain. Is that right? If so, I do understand what you're aiming for: Once a request has arrived at the new site, check whether the relevant file exists. If it doesn't, redirect to the root.

As written, this rule fires on every single request: not just pages but images, stylesheets, requests for robots.txt et cetera. So at an absolute minimum, constrain it to requests for pages:
RewriteRule (/|\.html)$ / [R=301,L]
This excludes requests for the root, which obviously does exist so you don't even need to check for it. Replace ".html" with whatever extensions you actually do use. I assume you're not extensionless, or the -f test would fail anyway. You also need to exclude requests for "index.html" because those will be handled separately.

#2a. The target of every RewriteRule (or Redirect) should include the full protocol plus-domain name. So it becomes
RewriteCond %{REQUEST_URI} !index\.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (/|\.html)$ http://www.example.com/ [R=301,L]


Why you don't want to do this:
Redirecting nonexistent pages to the root-- with or without the changed-site aspect-- is what Google calls a "soft 404". Users and search engines both hate it. (This is not always the case ;)) If there's no way to target the redirects on the old site, it's better to let them land on your nice customized 404 page.

But really, 200 pages is not a vast number. What you can and should do is make two rules. Both will live in the old site's htaccess.

RewriteRule ^({list-of-specific-pages-here}) http://www.example.org/$1 [R=301,L]

RewriteRule (/|\.html|^)$ http://www.example.org/special-new-page.html [R=301,L]

Or, depending on number of pages involved:

RewriteRule ^({list-of-specific-pages-here})?$ http://www.example.org/special-new-page.html [R=301,L]

RewriteRule (/|\.html)$ http://www.example.org/$1 [R=301,L]

Note that either way, requests for the root go to "special-new-page.html". This is a page that explains that the site has moved, and the exact page no longer exists, but here are some other things you might like to try.

How you handle non-page requests really depends on how important image files are to your site. For myself I'm happy to just serve 404s if it doesn't fit into an existing redirect pattern.

:: detour to own htaccess ::

As it happens, I moved recently. No -f issues, because mine was a page-for-page move covering certain named directories. Here are two of my redirects from the old site. This is not a cut-and-paste, but you get the idea:

RewriteRule ^(hovercraft|fonts|fun|ebooks|paintings|silence)(/index\.html)?$ http://example.com/$1/ [R=301,L]

RewriteRule ^((?:hovercraft|fonts|fun|ebooks|paintings|silence)/.*) http://example.com/$1? [R=301,L]


The first rule takes care of two things concurrently: the index.html redirect and the directory-slash redirect. Normally the latter is handled in mod_dir and you don't even need to think about it; here I was able to add it as a time-saver. The second rule covers all other requests. The trailing ? is to get rid of garbage, since none of my URLs have queries.


in a few days all indexed pages of the old site will disappear from Google

Unless yours is an enormously popular site, it will take much more than a few days. As of today, my old site still lists
:: detour to look up ::
47 pages. The correct number is between 10 and 20. In my case, the biggest plummet was between 1 and 4 weeks after the move:
original 289
week 1 272
later weeks: 228, 160, 104
with further ongoing drops at a slower rate. The list of Content Keywords gives some hints about which pages were dropped in which order-- but this is notoriously inexact and lags several weeks or even months behind.

Kirsten659



 
Msg#: 4651472 posted 10:57 am on Mar 7, 2014 (gmt 0)

Thank you for the detailed reply!

After reading your post we have decided not to send every page or request to the homepage of the new site but only do that with the "content pages". On that homepage of the new site, they get an explanation about the new site (so no need for a separate explanation page like in your suggestion).
All the other pages will get a customised 404.

How is the best way to do this?

I have tried it this way in the htaccess of the old site:

Redirect 301 /index.php http://www.newdomain.com/
Redirect 301 /dir/subdir/page1 http://www.newdomain.com/
Redirect 301 /dir/subdir/page2 http://www.newdomain.com/
Redirect 301 /dir/subdir/page3 http://www.newdomain.com/
...


But what I notice now, after a day is:
- that the new domain (the homepage) is indexed in Google without the www while I redirected it to the www version. How does this happen?
- the following page is indexed: www.newdomain.com/?1229904000671 providing duplicate content. How does this happen?

I hope you can help me out here.

Thanks,
Kristen

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4651472 posted 1:48 pm on Mar 7, 2014 (gmt 0)

You're better off using RewriteRule and suppressing appended parameters when you redirect.

You'll also need some additional rules on the new site to help clean up. The rules must be in the right order and all use RewriteRule syntax.

Kirsten659



 
Msg#: 4651472 posted 1:59 pm on Mar 7, 2014 (gmt 0)

Thanks for your reply.
The problem is that I'm not a developer and I can't find the correct code for this on Google...

What I now also notice is that the homepage of the old site now is indexed with the title and description of the new site while the indexed page of the old site should get replaced with the page of the new site (not just a change of title and description)...

I really would appreciate it if any of you experts could give me the code I should use in the htaccess.

Thanks a lot in advance!

Kristen

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4651472 posted 9:59 pm on Mar 7, 2014 (gmt 0)

mod_alias (Redirect by that name) can't do anything about parameters (the part after the question mark) or hostnames (the with/without www issue). So to clean everything up in a single step you'll need mod_rewrite in both places. Looks like I used example.org for the new site so let's stick with that.

RewriteRule ^({list-of-specific-pages-here}) http://www.example.org/$1? [R=301,L]

RewriteRule (/|\.html|^)$ http://www.example.org/special-new-page.html? [R=301,L]


Appending a ? to all targets means the query string will be left behind. Note that the ? means entirely different things in patterns and in targets, so remember which side of the blank space you're on :)

Then, on the new site-- in fact on all existing sites-- put two things at the end of all your redirects, after making sure everything has been translated to mod_rewrite:

RewriteRule ^(([^/]+/)*)index\.html http://www.example.org/$1 [R=301,L,NS]

RewriteCond %{HTTP_HOST} !^(www\.example\.org)?$
RewriteRule ^(.*)$ http://www.example.org/$1 [R=301,L]

For the first rule, some Apache installations may require a RewriteCond looking at THE_REQUEST. Mine (2.2.something) works fine with just the NS flag, making less work for the server.

What I now also notice is that the homepage of the old site now is indexed with the title and description of the new site

This will take up to several weeks to sort itself out. Possibly even longer if you're a tiny personal site like mine. Ignore it and it will eventually go away. You will also notice a bunch of "via this intermediate link" nonsense in the "who links to you" area. This too can only be ignored.

Kirsten659



 
Msg#: 4651472 posted 6:34 am on Mar 8, 2014 (gmt 0)

Thanks for your reply.

Some things arean't clear to me yet:
1) {list-of-specific-pages-here} => how do you put all the pages there? Can you please give an example?
2) I also notice that you still use /special-new-page.html We don't need that special page any more because the redirected pages get the new site info on the new site homepage (there only will be 1 page) and those that get a 404 will get a customized 404. Do I still need that rule then on the old site htaccess?
3) I notice a few times in your code .html Actually the old site has only an index.php in the root (the homepage), all other pages are indexed as a folder. There is not index.html of index.php in that folder. So all pages are like: www.oldsite.com/dir/pagename (without any .html or .php) Is the code then correct that you gave for the htaccess?

Thanks,
Kristen

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4651472 posted 9:54 am on Mar 8, 2014 (gmt 0)

#1 Like this (based on some rearranging I did just yesterday,* really ;)):

RewriteRule ^paintings/rats/(addrodent|catenary|hovercraft| howyousay|northstar|nuqqarit| pride|pusiruluk|snocone| snow|translation|uranium)\.html http://example.com/paintings/northrats/$1\.html [R=301,L]

#2 How does the custom 404 page work? If someone at the new site misspells a request, will they see a page that's geared toward people who were aiming for the old site?

If 404s are rare on the new site, this may not be a serious problem. Tangential thought: Those users who look at address bars will find themselves grumbling "Why did they bother to redirect me if the page isn't there after all?"

Alternative: If a page has no good equivalent at the new site, don't even send them there. Instead do a 410 in situ:

RewriteRule ^ebooks/(hale|downy|rambles|ninelives|christmas|grandmother)/ - [G]

(Yes, OK, it's easier to cut and paste than to make up new rules from scratch!) And then provide a really good 410 page at the old site.

#3. If you don't have any physical directories at all, you can simply ignore that aspect of redirecting. But, contrariwise, if you're 100% extensionless it also means your URLs are 100% rewritten. So then how would the -f and -d tests work?


* Yes, all right, past midnight, the day before yesterday.

Kirsten659



 
Msg#: 4651472 posted 2:31 pm on Mar 8, 2014 (gmt 0)

Thanks again Lucy for the detailed reply but it’s not yet completely clear to me :-(

Maybe it’s a good idea to give you some more info about the page-structure on the old domain.
We had there:

www.olddomain.be (the exact page there is www.olddomain.be/index.php)
www.olddomain.be/nl/keyword1 (“keyword1” is not really a directory but a rewrite of keyword1.html)
www.olddomain.be/nl/directory1/keyword2
www.olddomain.be/nl/directory1/keyword3
www.olddomain.be/nl/directory2/keyword4
www.olddomain.be/wordpressblog/blogpost1 (“blogpost1” is not really a directory but a rewrite of the blogpost pagename done by Wordpress)
www.olddomain.be/wordpressblog/blogpost2
….


And on the new domain you just have 1 page:
www.newdomain.com (the exact page there is www.newdomain.com/index.php)
Actually the new domain has exactly the same name as the old domain. The only difference is that it has the extension .com instead of .be (because we want to work more internationally now).

About the custom 404-page: It’s just a 404 page that says that the page you are trying to visit was existing on our old website but doesn’t exist any more because the old site has been replaced by a new site. Below that info they can click a link if they want to go to the new site.

So actually we want to redirect all the content pages of our old site (about 40 or so) with a 301 to the new site in the hopes to transfer some pagerank, linking credit,… to the new site but also because most of the visitors of those pages will actually want to see our new site.
All the other pages of the old site (like the page with the terms, privacy policy, pages with content that’s irrelevant to the new site,…) will get the 404 page.
And the only page that still has to remain in the serps is www.newdomain.com. All other pages should be removed from the serps.

I hope this explains it a little bit more.
And I really hope that you can tell me now exactly what I need to type in the htaccess to do this? :-))

Thanks a lot!

Kirstin

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4651472 posted 10:11 pm on Mar 8, 2014 (gmt 0)

actually we want to redirect all the content pages of our old site (about 40 or so) with a 301 to the new site in the hopes to transfer some pagerank, linking credit,… to the new site but also because most of the visitors of those pages will actually want to see our new site.
All the other pages of the old site (like the page with the terms, privacy policy, pages with content that’s irrelevant to the new site,…) will get the 404 page.


It sounds as if you may want an "everything except" redirect. It looks like this:

# 1
RewriteRule ^(boilerplate|contact|info) - [G]


Rule 1: For pages that aren't moving, serve a 410 at the old site. Give a useful 410 page explaining about the move. This rule is easiest to write if you can block out entire directories. For directories that are only partly moving, you'll need more detail. So Rule 1 may really be Rules 1a through 1f:

# 1b
RewriteCond %{REQUEST_URI} !(chocolate|cigars|calendars)
RewriteRule ^sales - [G]


meaning "everything in the /sales/ directory is now gone, except the three listed pages". And then the same thing for any other partial directories. If a directory has twelve pages and you're moving ten of them, turn it around:

# 1c
RewriteRule ^hotels/(Brussels|Antwerp) - [G]


meaning "these two pages in /hotels/ are gone".

I imagine some of these pages are noindexed already; who indexes a "contact us" or site-search page?

# 2
RewriteRule ^index\.php http://www.example.org/ [R=301,L]


Rule 2: You always need an index redirect, so let's combine it with the new domain name.

# 3
RewriteRule (.*) http://www.example.org/$1 [R=301,L]


Rule 3: covers all pages that weren't addressed in #1 and #2: "anything that's left over gets redirected". It also covers any requests for the root (which goes to the root of the new domain). If you don't want to redirect the root, change #3 to say
(.+)
instead of
(.*)
and in #2 put the old domain name as target.

And the only page that still has to remain in the serps is www.newdomain.com.

When your fingers typed "newdomain" did they mean "olddomain"? You want everything indexed as newdomain, right?

All those # may look like "number" symbols, but they're really the Apache "comment" marker ;)

Note finally that if you're using extensionless, rewritten URLs, you cannot use the simple -f test. You might still be able to do something involving %{REQUEST_URI}\.php but it's messier and more complicated. Stick with explicit filenames if you know them.

Kirsten659



 
Msg#: 4651472 posted 10:11 am on Mar 9, 2014 (gmt 0)

Thanks again for your reply but it's still too complicated for me :-(
I will try to explain/simplify my question some more:

Let's say that the old website has 100 pages.
We want all pages to receive a 404 except the following 7 pages:

www.domain.be (the exact page there is www.domain.be/index.php)
www.domain.be/nl/keyword1 (“keyword1” is not really a directory but a rewrite of keyword1.html)
www.domain.be/nl/directory1/keyword2
www.domain.be/nl/directory1/keyword3
www.domain.be/nl/directory2/keyword4
www.domain.be/wordpressblog/blogpost1 (“blogpost1” is not really a directory but a rewrite of the blogpost pagename done by Wordpress)
www.domain.be/wordpressblog/blogpost2


We want those 7 pages to get redirected with a 301 to the root of www.domain.com (so domain.com is the new URL while domain.be is the old URL and domain.com only has a homepage, no inner pages).

So there's no problem with 93 of the 100 pages because they already receive the customized 404.
We just want to redirect the 7 pages with a 301 to the new webpage (preferably moving also as much pagerank and linking credit as possible.

How do we do this correctly?
If possible, can you give me the exact code to put in the htaccess because I honestly have a very hard time understanding your examples.

You would do me a very big favour with that! :-)

Thanks,
Kirsten

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4651472 posted 8:34 pm on Mar 9, 2014 (gmt 0)

You keep saying 404. But really it's 410 meaning "I removed this page on purpose". On paper, google doesn't distinguish between the two. Maybe it really doesn't, for indexing purposes. But it definitely stops crawling a lot sooner when it receives a 410 response. (Bing doesn't seem to care.)

For humans it means a different error document. Most people don't have a custom 410 page, but you should make one, because the Apache default is scary. In ordinary circumstances you can simply declare the same physical document as you use for 404; here a separate one is appropriate:

ErrorDocument 410 /itsgone.html

This goes in the old site's htaccess.

We want those 7 pages to get redirected with a 301 to the root

Now, wait a minute. What ever happened to redirecting some content pages to individual equivalent pages on the new site?

For rule-making purposes it doesn't matter, though. The principle is the same: do such-and-such to certain requests, and anything left over will get the default handling. If only a few pages are to be redirected, then that rule goes first.

With customized redirects it looks like this. Still in the old site's htaccess:
RewriteRule ^(index\.php)?$ http://www.example.com/ [R=301,L]

RewriteRule ^nl/directory1/(keyword1|keyword2|keyword3) http://www.example.com/directory1/$1 [R=301,L]

RewriteRule ^nl/directory2/keyword4 http://www.example.com/directory2/keyword4 [R=301,L]

RewriteRule ^wordpressblog/(blogpost1|blogpost2) http://www.example.com/wordpressblog/$1 [R=301,L]


Now, at this point, all the special 7 requests have been redirected and are no longer on the old site. So any requests that continue past this point will not be redirected and will instead meet the last rule:

RewriteRule . - [G]

and that's all.

All of this happens in the old site's htaccess. I think google recommends keeping the old site alive for 6 months just for redirecting purposes. If you're paying a lot for hosting you should be able to cut back to a cheaper level, since you're now only serving up redirects and 410s.

You definitely want to hold on to the example.be domain name, if only to prevent the dragons from snapping it up. You may need it again later and it's cheaper to keep it.

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