Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect not working as I want it

         

raerae

4:42 pm on Jun 15, 2007 (gmt 0)

10+ Year Member



Hi There everyone,

I'm new here and did a quick search, but could not find an answer to my problem.

I am trying to redirect all the pages from one domain to another. What has happened is that the site was originally built and hosted with a .cc domain. The .com version of the domain just came available and we want all the pages from the .cc domain to redirect to the .com domain.

We have set up a separate hosting account for the .cc site and I implemented the following re direct:

RedirectMatch 301 ^(.*)$ http://www.example.com

It is working in that pages to redirect, but they only redirect to the home page, and not their equivalent on the .com site.

For example I want to redirect www.example.cc/pageone to www.example.com/pageone.

I was under the impression that the above command would accomplish this.

I have also tried inputing each individual page into the .htaccess file and they still all redirected to the home page using the standard 301 redirect command. However, it does work if I just place one line for one page in there...

Can anyone provide any insight to why this may be happening - did I use the RedirectMatch command incorrectly?

Thanks so much!

Raerae

jdMorgan

6:13 pm on Jun 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The syntax you used specifies the behaviour you're observing -- You've told it to drop the local URL-path.

Use any of the following to redirect to the new domain while retaining the local URL-path:

 RedirectMatch 301 (.*) http://www.example.com[b]/$1[/b] 

or
 Redirect 301 / http://www.example.com/ 

or
 RedirectPermanent / http://www.example.com/ 

When using RedirectMatch, enclosing a pattern or subpattern in parentheses creates a back-reference. The value matching the (sub)pattern can then be "back-referenced" in the new URL by number, with the number corresponding to back-references numbered according to the left-parenthese count. If the (sub)pattern's value is not back-referenced, it is simply dropped.

When using the Redirect directive, any part of the URL-path not specified in the prefix-match on the left is appended to the URL specified on the right.

So, any of the examples above will do what you need.

Jim

raerae

6:25 pm on Jun 15, 2007 (gmt 0)

10+ Year Member



Thank you!

It's working perfectly now. FWIW I used the first example as the other two also redirected back to the home page.

Thanks again!

Raerae

jdMorgan

7:02 pm on Jun 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> as the other two also redirected back to the home page.

More likely, you didn't flush your browser cache after changing the code, so your browser simply served you the previously-cached redirect response...

Jim

raerae

7:05 pm on Jun 15, 2007 (gmt 0)

10+ Year Member



Thanks - that's probably what it was! Thanks again for your help - this was the first 301 redirect I've implemented myself and I really appreciate it!

phranque

8:46 pm on Jun 15, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, raerae!

you found the right place!
jim usually answers apache questions expertly (especially mod_rewrite) before i get a chance to read them...