Forum Moderators: phranque

Message Too Old, No Replies

Redirecting the home page to new site

301 redirect for the home page of a website

         

Daveyboy33

8:50 am on Jun 18, 2010 (gmt 0)

10+ Year Member



Hello,
I wondered if anyone might be kind enough to help with this issue, which I feel that I might be overcomplicating a little.

Suppose I have a website and I've moved it to a new domain name, but in the move I've renamed some of the pages since the old page names were not very well thought out.

Since the page structure is different I can't just redirect the whole site since I might have:

oldsite.com/oldpagename.html redirecting to newsite.com/newpagename.html

Redirecting the inner pages is easy enough with a straightfoward 301 redirect, but the thing I'm struggling with is how do you redirect the home page of the old site to the home page of the new site?

Do I just do a 301 redirect for index.html to the homepage of the new site?

Also, if this is what you do, how would you redirect the home page if it was say a wordpress site where you don't have an index.html file?

Many thanks in advance.

Dave

Daveyboy33

9:03 am on Jun 18, 2010 (gmt 0)

10+ Year Member



PS

I forgot to mention - the thing thats confusing me with this is that the site hasn't ever had mod rewrite used to stop the issue with:

oldsite.com and oldsite.com/index.html both appearing.

So I'm confused as to whether redirecting index.html will just redirect the /index.html version above.

Thanks.

g1smd

9:45 am on Jun 18, 2010 (gmt 0)

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



Redirect the old site www and non-www URLs for both / and /index.html to www.example.com/ at the new site.

RewriteRule ^(index\.html)?$ http://www.example.com/? [R=301,L]


The Redirect also removes any parameter string data appended to the old URLs too.

You don't need to think about "files" here. The redirect deals with URL requests coming from the browser. If a certain URL is requested, the redirect is invoked to tell the browser to go request a different URL. For this request the server never gets as far as looking at any files inside the server.

[edited by: g1smd at 9:59 am (utc) on Jun 18, 2010]

Daveyboy33

9:54 am on Jun 18, 2010 (gmt 0)

10+ Year Member



"Redirect the old site www and non-www URLs for both / and /index.html to www.example.com/ at the new site.

RewriteRule ^(index.html)?$ http://www.example.com/? [R=301,L] "

Hello, thanks for your help.

So the code above will do that and in effect solve the problem?

And for the other pages I'd just use a 301 redirect as usual too?

Thanks again,
Dave

g1smd

10:00 am on Jun 18, 2010 (gmt 0)

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



Use
RewriteRule
for all of the rules.

If you use RewriteRule (for either redirects or rewrites) then never mix that with Redirect or RedirectMatch directives on the same site.

Daveyboy33

10:59 am on Jun 18, 2010 (gmt 0)

10+ Year Member



Right thanks.

Am I right in thinking that for the other pages then I'd put:

RewriteRule ^(oldpagename.html)?$ http://www.example.com/newpagename.html [R=301,L]

Thank you

g1smd

1:17 pm on Jun 18, 2010 (gmt 0)

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



No, for those you omit the ( ) and ? as they are only needed on the index.html rule.

For the original index.html rule the ( ) ? syntax allowed a match for /index.html and for / requests too.

If you use ( ) ? again, you'd have a second rule that was trying to match requests for / again.

Don't forget to escape the literal reriod in your regular expression pattern.

Daveyboy33

1:31 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



Don't forget to escape the literal reriod in your regular expression pattern. :o

Sorry, I don't understand what that means at all, I'm not so hot with this stuff.

Would you mind explaining please?

Should it be:

RewriteRule ^oldpagename.html$ http://www.example.com/newpagename.html [R=301,L] or something else?

Many Thanks, sorry for being a pest.

Thanks,
Dave

g1smd

1:57 pm on Jun 18, 2010 (gmt 0)

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



The pattern
^page[b].[/b]html$
will match
page[b].[/b]html
and
page[b]Z[/b]html
and
page[b]5[/b]html
as the "dot" matches "any single character".

If you want to match the literal
page.html
then you need
page[b]\[/b].html
in your pattern. The pattern now matches
page "DOT" html
only.

Escaping is only needed in your patterns. It is never needed in the target filepath or target URL.

Daveyboy33

2:07 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



Thank you very much g1smd, you are a star!

Kind Regards,
Dave