Welcome to WebmasterWorld Guest from 54.226.62.26

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Simple 301 (external) Redirect Gone Awry

301 redirect one set of site pages to corresponding pages on new domain

     

Canton

6:44 pm on Apr 7, 2011 (gmt 0)

10+ Year Member



I *thought* what I was trying to do here was easy, but I've run into a problem that I believe is related to a lack of understanding on syntax.

I'm trying to redirect a handful of pages from one domain/site to a corresponding set of pages on a new domain/site. I'm forwarding the home page of the old to the home page of the new, then about a dozen other pages in the old site to corresponding pages on the new site.

Here's what I've got:

redirect 301 / [newsite.com...]
redirect 301 /about/ [newsite.com...]
redirect 301 /file1/ [newsite.com...]
redirect 301 /file2/ [newsite.com...]

Simple as that, but only the home page of the old site redirects to the proper page, i.e. - the home page of the new site.

The second directive, for example, redirects to: http://www.newsite.comabout, leaving off the trailing slash between the domain and the file name, thus leading to a 404 error.

I've tried escaping that forward slash (though I firmly believed this was unnecessary) as well as wiping out my old site (temporarily) that it consisted ONLY of the .htaccess file. Neither worked, but any input is much appreciated.

~Canton

g1smd

6:51 pm on Apr 7, 2011 (gmt 0)

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



The first rule redirects example.com/<anything> to newsite.com<anything> automatically re-appending the path information from the original request.

None of the other rules get to run.

Fix this by using RewriteRule syntax, a more precise pattern, the new domain name as before, and the [R=301,L] flags to signify the redirect.

Order the rules from most specific, to more general. For the root home page redirect, redirect to newsite.com/ with a trailing slash and NOT to any named index page.

Canton

8:10 pm on Apr 7, 2011 (gmt 0)

10+ Year Member



Thanks g1smd - off to do some research. Working with regular expressions and .htaccess is just not my forte.

~Canton

g1smd

8:16 pm on Apr 7, 2011 (gmt 0)

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



Try the resources listed and linked from the forum charter and the thousands of examples here in the forum.

Canton

8:30 pm on Apr 7, 2011 (gmt 0)

10+ Year Member



Hmmm...I tried something that doesn't test my limited (nonexistent) abilities on this front and it appears to work, namely:

RedirectMatch 301 /about/ [newsite.com...]
RedirectMatch 301 /file1/ [newsite.com...]
RedirectMatch 301 /file2/ [newsite.com...]
RedirectMatch 301 / [newsite.com...]

I just made sure the home page redirect was last (as noted in the example) and it appears to forward fine. I only have 28 pages to forward, so it's pretty easy to manage, but I don't know *for sure* that this is "clean." Any suggestions for testing, or does this look legitimate?

g1smd

8:52 pm on Apr 7, 2011 (gmt 0)

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



Yes, but you're better off in the long run ignoring Redirect and RedirectMatch and using RewriteRule instead. The syntax is similar, but there is a LOT more power in mod_rewrite.

Canton

9:35 pm on Apr 7, 2011 (gmt 0)

10+ Year Member



Thanks - I'll use what I have for now until I can learn more, then improve when I have to do something like this again. I appreciate the input and the guidance!

g1smd

9:55 pm on Apr 7, 2011 (gmt 0)

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



In particular check what happens if you request example.com/index.html from the old site.

Canton

2:48 pm on Apr 9, 2011 (gmt 0)

10+ Year Member



Sorry - been away from the computer for a few days (an oddity). Now, I'm assuming that a request for oldsite.com/index.html would present some problems with the format I've used?

Luckily (though not for purposes of illustration), I don't have a file structure like that. The nature of the previous .htaccess file for the old site issued a 301 redirect (I believe it was a 301) back to the domain itself - without the file extension - if that particular file (home page) was requested, i.e. - oldsite.com/index.html always went back to oldsite.com. I also didn't use any file extensions at all, so that the oldsite.com/about/ page I referenced is, in fact, a "page" in the site and not a directory. The new site is the same, though without the trailing slash on individual pages/files.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month