301 REDIRECT HELP in Apache

Posted By: SmartROI ()
Posted On: 2005-Nov-07 00:08

Hey maybe you all can help me with a problem I'm having.

One of my client sites is showing up something like:

client.com
www.client.com
www.host.com/~client/
host.com/~client/

and I want everything to show up as www.client.com instead of all the variations.

currently in apache .htaccess I've tried.

301 Redirect / http;//www.client.com
it doesn't work. This works...

301 Redirect oldpage.php http;//www.client.com/newpage.htm

(with : instead of ; )

but that's not the problem. The problem is that I want all the index.htm pages and all pages on the site to resolve as the full URL for www.client.com/
(with the WWW)





Posted By: g1smd (Staff)
Posted On: 2005-Nov-07 00:50

This bit is correct for sure:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^client.com [NC]
RewriteRule ^(.*)$
http://www.client.com/$1 [L,R=301]


I am not sure how to handle the folder part, so this bit might not work:

RewriteCond %{HTTP_HOST} ^host.com/~client/ [NC]
RewriteRule ^(.*)$
http://www.client.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.host.com/~client/ [NC]
RewriteRule ^(.*)$
http://www.client.com/$1 [L,R=301]


This all goes in the .htaccess file in the root folder of the site.


Posted By: SmartROI ()
Posted On: 2005-Nov-07 08:44

Uh oh.

When I do just the top part and type in

client.com
instead of www.client.com

the resulting page is a 404 error page.

Likewise with client.com/page.htm

Bottom part didn't work at all . sad





Posted By: lizardz ()
Posted On: 2005-Nov-08 06:53

"www.host.com/~client/"

this means that the hoster is already using some type of rewriting to direct requests for your client's site to that folder.

There is one and only one solution that is even worth spending more than a few seconds here: move to a real webhoster and stop wasting your time.

Trying to work with junk webhosting is a total waste of your time. If I had a client that asked me to do that I'd tell them politely that every problem I run into with the bad hoster will be billed at $100 per hour. Or they can just move to a real hoster.


Posted By: g1smd (Staff)
Posted On: 2005-Nov-09 00:43

Right. Try this:


Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^client\.com [NC]
RewriteRule ^(.*)$
http://www.client.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^host\.com [NC]
RewriteRule ^~user/(.*)$
http://www.client.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.host\.com [NC]
RewriteRule ^~user/(.*)$
http://www.client.com/$1 [R=301,L]


Remove all the blank lines from within the code.

Add a blank line after the last line of the code.

[ Message was edited by: g1smd 11/09/2005 06:25 am ]




Posted By: SmartROI ()
Posted On: 2005-Nov-09 01:26

"move to a real webhoster "

Shoot... now I have to either fire myself or charge myself $100 an hour.




Posted By: lizardz ()
Posted On: 2005-Nov-09 01:56

It crossed my mind as I posted that that maybe you were hosting the site yourself.

But you've setup your server wrong in that case, that's not how you do it, you want to use virtual name based hosting, it doesn't work like the way you're doing it now, it just allows apache to handle all requests for different domains without using that folder hack.

I have maybe 50 sites running on my local server, each is a real site, accessible at the flick of a switch over the web, if I point all the dns stuff to them and open up my port 80 etc. You can't reach any of them unless you put in the correct domain name.

I would do both, fire yourself, and charge $100 an hour to fix the setup, that way you'll get a nice break, and also some good pocket change. Plus you'll have real site addressing etc as a bonus. Win win win.

If I remember my IIS right, and I'm really stretching my memory here, this is totally possible with IIS too, it's really easy setting up new sites there too that are standalone.

If it's apache though, and if you have access to httpd.conf, this is really easy to do.

I've noticed a certain tendency to not learn how to set up multiple sites on apache, I don't know why that is, maybe because the xamp packages don't do that by default, don't ask me, no idea, but it's really easy to do it right.


Posted By: g1smd (Staff)
Posted On: 2005-Nov-10 15:09


Did the new code, above, help at all?


Posted By: SmartROI ()
Posted On: 2005-Nov-11 21:23

Well folks. thanks for the help. I finally got ahold of one of our techs and he made some adjustments in apache I believe.

So, the htaccess help is no longer needed. Thanks though!

Tony


Posted By: lizardz ()
Posted On: 2005-Nov-11 21:31

Oh, it's apache, yes, all that's required is setting up virtual sites, in httpd.conf, and adding the 301 into each virtual site directory. It's pretty easy.

httpd.conf changes are always preferable to .htaccess, but almost no shared hosting will allow users to touch httpd.conf, since any error will crash all the shared sites. But httpd.conf changes are more efficient, since apache boots up with those changes locked in, .htaccess changes have to be processed each page request, over and over.

Wait, does this mean you didn't have to fire yourself? And you didn't have to pay yourself $100 an hour? That's probably good.


Posted By: g1smd (Staff)
Posted On: 2005-Nov-12 02:54

Now use WebBug to check that three of the URL variations give a 301 redirect for any page of the site that you try to access, and the fourth returns the correct page with status of "200 OK".