Setting up redirects for websites on a VPS

Using a single web hosting account to host multiple sites

Setting up redirects for websites on a VPS

Postby eJM » Sun Nov 23, 2008 12:22 pm

Like many, I have a several domains in my VPS account. The main domain the host account was set up with is enterprisejm.net, which is in the public_html root, and the rest of my domains are set up in folders in public_html. The structure looks something like this:

enterprisejm.net (aka public_html)
.htaccess
index.html
[domain1-folder]
[domain2-folder]
[domain3-folder]

My mod rewrite routine doesn't seem to work properly. I do have the redirect to non-www status for enterprisejm.net, but when it comes to redirecting, for instance, enterprisejm.net/domain1-folder to domain1.com, it doesn't work right. It redirects to domain1.com, but to a 404 error page instead of the home page.

I have this redirect in the .htaccess file that was automatically put there by the cPanel redirect feature:
Code: Select all
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^1foot/?$ "http\:\/\/domain1\.com" [R=301,L]

When I type enterprisejm.net/domain1-folder in the browser's address bar, I get domain1.com//home/ejm/public_html/domain1-folder, which results in a 404 page at domain1.com.

When I type domain1-folder.enterprisejm.net in the address bar, I get the domain1.com home page, just as it is s'posed to do.

What I want is when someone (or a search spider) follows a link that refers to any folder on enterprisejm.net that belongs to another domain, I want it to be directed to that domain's home page.

I hope I haven't confused anyone. To summarize:

domain1-folder.enterprisejm.net should redirect to domain1.com
enterprisejm.net/domain1-folder should redirect to domain1.com

As a side note, I have some domains set up to use www and some don't. I have the rewrite in each of the .htaccess files in the domain folders to take care of that, but I don't know if that is necessary to set up in the enterprisejm.net .htaccess file too.

Thanks for any help with this.

Jim
eJM
 
Posts: 3
Joined: Sun Nov 23, 2008 11:46 am
Location: teh Ether

Postby richardk » Sun Nov 23, 2008 2:22 pm

You'd get a better set up if you used Name-based Virtual Hostss in the httpd.conf file.

But try in /public_html/.htaccess
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# enterprisejm.net/example1/ to example1.com/
RewriteCond %{HTTP_HOST} ^(www\.)?enterprisejm\.net$ [NC]
RewriteRule ^example1(/(.*))?$ http://example1.com/$2 [R=301,L]

# example1.enterprisejm.net/ to example1.com/
RewriteCond %{HTTP_HOST} ^example1\.enterprisejm\.net$ [NC]
RewriteRule .* http://example1.com%{REQUEST_URI} [R=301,L]

# Remove www. from enterprisejm.net
RewriteCond %{HTTP_HOST} ^www\.(enterprisejm\.net)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


Or this in /htdocs/.htaccess
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Remove www. from enterprisejm.net
RewriteCond %{HTTP_HOST} ^www\.(enterprisejm\.net)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

and this in /public_html/example1/.htaccess
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# enterprisejm.net/example1/ to example1.com/
# example1.enterprisejm.net/ to example1.com/
RewriteCond %{HTTP_HOST} ^((www|example1)\.)?enterprisejm\.net$ [NC]
RewriteRule ^(.*)$ http://example1.com/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby eJM » Sun Nov 23, 2008 3:41 pm

richardk wrote:You'd get a better set up if you used Name-based Virtual Hostss in the httpd.conf file.

Thank you very much for your quick reply, Richard. The above was an interesting read too. Can you quickly explain "better setup" for me? Would there be faster server response to the domain requests? Is there more security with using Name-based Virtual Hosts?

If I opt to add one or more IP addresses to my account, it sounds like that would be a much more efficient way to control the document requests. Is that correct? Even with the single IP I use now, would this be more efficient use of server resources?

I am going to hold off on the 301 redirects until I hear back on these questions. Of course, you prob'ly already know that the reason so many of us come here for answers is because the documentation at apache.org is a very difficult read and sometimes even harder to understand. :o

Thank you for your help.

Jim
eJM
 
Posts: 3
Joined: Sun Nov 23, 2008 11:46 am
Location: teh Ether

Postby richardk » Mon Nov 24, 2008 12:53 pm

Can you quickly explain "better setup" for me? Would there be faster server response to the domain requests? Is there more security with using Name-based Virtual Hosts?

The main reason is you could have totally seperate document roots instead of having the other domains inside your main domain's document root. You probably already have <VirtualHost>s, but they're just set to sub directories of your main document root.

I don't think you would get an speed increase or security increase (although you can probably add security settings if you manually set up <VirtualHost>s).

It's probably not a big deal, so think about it before you change. You might even be able to do a mix of the two.

If I opt to add one or more IP addresses to my account, it sounds like that would be a much more efficient way to control the document requests. Is that correct? Even with the single IP I use now, would this be more efficient use of server resources?

What are you going to use multiple IP addresses for? You can do IP based Virtual Hosts, but i don't think there's much point if you can do them based on the domain.

I am going to hold off on the 301 redirects until I hear back on these questions.

They won't do much harm. You would still want example1.enterprisejm.net redirected to example1.com, wouldn't you?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby eJM » Mon Nov 24, 2008 1:55 pm

richardk wrote:The main reason is you could have totally seperate document roots instead of having the other domains inside your main domain's document root. You probably already have <VirtualHost>s, but they're just set to sub directories of your main document root.

I don't think you would get an speed increase or security increase (although you can probably add security settings if you manually set up <VirtualHost>s).

It's probably not a big deal, so think about it before you change. You might even be able to do a mix of the two.

Thanks again for your help, Richard. My only experience with hosts has been through shared host accounts, until I moved to my VPS at KnownHost. It appears that this is a different environment and I have more options on how to set things up. Unfortunately, I never knew there were other options.

I want to do it the most efficient way possible. I just had a friend contact me this morning and he wants me to build a couple sites for him and put them on a VPS of his own - same company I use. Even if I don't change the way I have been doing things on my own VPS (which it sounds like it might be better if I did change), I want to make sure I set him up properly.

The "mix of the two" might be best left to those sites I have duplicate domain names for - like thefloorpro.com and thefloorpro.net, etc. But because I seem to be wading into the unknown for me, I'll wait for guidance. Yours would be appreciated.

What are you going to use multiple IP addresses for? You can do IP based Virtual Hosts, but i don't think there's much point if you can do them based on the domain.

I was going to add IP addresses only so that some websites would have different IP addresses. I understand there is some debate as to its value when you do link trading. I have several flooring related sites, but they are all on the same IP. I thought if there was even the slimmest chance my ranking would improve if the IP's were different, I would do it. The cost is very reasonable. I didn't plan to use multiple IPs for the same site.

you wrote:
I wrote:I am going to hold off on the 301 redirects until I hear back on these questions.

They won't do much harm. You would still want example1.enterprisejm.net redirected to example1.com, wouldn't you?

I heard back from the tech support person at KnownHost and they set up redirects that seem to work well. In the .htaccess file on the main account domain, enterprisejm.net, this is what they used:
Code: Select all
Options +FollowSymLinks
DirectoryIndex index.php index.html index.htm
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.enterprisejm\.net$
RewriteRule ^(.*)$ http://enterprisejm.net/$1 [R=permanent,L]

redirect 301 /1foot http://1footinthegrave.com
redirect 301 /afpnet http://afloorpro.net
redirect 301 /ejmcom http://www.enterprisejm.com

The first rule, as you know, limits the domain to enterprisejm.net without the www. Then there are just simple redirect rules that send requests for any of the domain folders to the domain home page. And it's done in a way that preserves whether I have chosen to use www or not. In each domain folder is another .htaccess file that looks like this:
Code: Select all
Options +FollowSymLinks
DirectoryIndex index.php index.html index.htm

Of course, there is more, depending if I have WordPress or other domain directives. But there is no RewriteEngine on or RewriteBase / lines. It works when I tested it on the 3 domains so far. I was in the process of adding all the rest of the redirects when I got notified of this topic reply.

As you say, it certainly won't hurt to continue with the redirects, so I will. But I do await any advice you may have concerning the structure I use in the VPS. Thank you very much for all your help.

Jim McClain
eJM
 
Posts: 3
Joined: Sun Nov 23, 2008 11:46 am
Location: teh Ether

Postby richardk » Tue Nov 25, 2008 4:54 am

But because I seem to be wading into the unknown for me, I'll wait for guidance.

Maybe set up Apache on your home computer so that you can see if you would be confident manually configuring a live server.

I want to do it the most efficient way possible.

It's less about efficiency and more about control. You could choose whatever document root you wanted, add Aliases or RewriteMaps, etc.. But if you don't need any of that then it might not be worth the hassle of all the configuration responsibility.

I want to make sure I set him up properly.

The person who will maintain the server needs to be confident with the configuration.

I was going to add IP addresses only so that some websites would have different IP addresses. I understand there is some debate as to its value when you do link trading. I have several flooring related sites, but they are all on the same IP. I thought if there was even the slimmest chance my ranking would improve if the IP's were different, I would do it. The cost is very reasonable. I didn't plan to use multiple IPs for the same site.

I doubt that is true. There a millions of high ranked websites on share hosts.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 23 guests

cron