redirect main domain only on shared hosting

Using a single web hosting account to host multiple sites

redirect main domain only on shared hosting

Postby benoka » Sun Oct 25, 2009 2:32 pm

Hi,

I'm using shared hosting at GoDaddy, meaning that there's a default domain name and all other domains are sharing the same server space although they can be linked directly from their domain names if the linked files are in their associated subfolders.

As I'm not using the default main domain for anything but I have several subdomains, pages in subfolders and obviously multiple other domains that need to run, I'm trying to redirect my default main domain ONLY to an external blog of mine.

This is the code I'm using:

Code: Select all
ErrorDocument 404 /

Options +FollowSymLinks

RewriteEngine on

RewriteCond %{HTTP_HOST} ^subdomain\.maindomain.com
RewriteRule .* - [L]

RewriteRule (.*) http://external.blog.com/$1 [R=301,L]

As I read about, this was meant to only let the subdomain redirection go through and nothing else, however it seems that everything goes through except for the main domain that rightly gets redirected to the blog.

Can you explain why? Is there a "cleaner" way to setup htaccess to only redirect the main domain or do I have to choose all the exceptions (the ones that can go through?

Simply 301 redirecting the root will not allow to access any subdomains or subfolders however I would like to have that.

Also, if possible, the error page should go to the blog's main page and not to an error page of the blog as it does now.

Thank you very much for your help in advance!

ben
benoka
 
Posts: 23
Joined: Fri Jun 19, 2009 9:23 am

Postby benoka » Sun Oct 25, 2009 2:42 pm

additionnally to the above code: it unfortunately doesn't let me link images to the blog. how is it possible that a page in a subdomain of the default main domain (that is not included in the .htaccess exception list) gets displayed but not the images i linked to the external blog?
benoka
 
Posts: 23
Joined: Fri Jun 19, 2009 9:23 am

Postby richardk » Mon Oct 26, 2009 10:18 am

I'm using shared hosting at GoDaddy, meaning that there's a default domain name and all other domains are sharing the same server space although they can be linked directly from their domain names if the linked files are in their associated subfolders.

Do the domains have seperate document roots (eg. example.com to /public_html/example.com and example.net to /public_html/example.net)? What are they like?
What are the sub domain document roots?

As I'm not using the default main domain for anything but I have several subdomains, pages in subfolders and obviously multiple other domains that need to run, I'm trying to redirect my default main domain ONLY to an external blog of mine.

Match the domain you want to redirect
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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


As I read about, this was meant to only let the subdomain redirection go through and nothing else, however it seems that everything goes through except for the main domain that rightly gets redirected to the blog.

Can you explain why?

I would guess it has to do with document roots or .htaccess files in the other domain/sub domain directories.

Also, if possible, the error page should go to the blog's main page and not to an error page of the blog as it does now.

What error page? Probably not as the errors would occur on the external server and mod_rewrite on this server has no control of the external server.

additionnally to the above code: it unfortunately doesn't let me link images to the blog. how is it possible that a page in a subdomain of the default main domain (that is not included in the .htaccess exception list) gets displayed but not the images i linked to the external blog?

An example <img> src="" would be?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby benoka » Tue Oct 27, 2009 12:47 am

Thank you very much for your superfast response!

Do the domains have seperate document roots (...) What are the sub domain document roots?

yes, their document roots are the ones I setup for them when I add them to my account (exactly as in your example); subdomain document roots can be setup exactly the same way. my main folder I created is called websites and I created subfolders here for all my domains and subdomains separately.

error page = i meant 'ErrorDocument 404' - i put this line at the very top of the .htaccess file, so i guessed it will execute before going to the blog. I realized i set it up to go to the root ('/') so of course it was passed over to the blog and displayed the blog's error page. I now replaced that with the exact URI of the blog, but it still displays the blog's error page, however what I would like to have is to simply go to the blog's main page, no error document needed. By the way, I setup an error page at the blog and tried to setup .htaccess to send 404 requests there but it simply sends the requested URL to the redirected blog like this: somthing.blog.com/[wrongfilename] and displays the blog's standard error message instead of the one I set in .htaccess. Does it mean that the only way to setup an errordocument is if the document is placed on my server? i cannot send those to a specific page on the external blog?

An example <img> src="" would be?

http://maindomain.com/images/example.jpg - the picture i setup for my external blog as a background doesn't display with the .htaccess I just setup on your advice above. i guess the image requests are also redirected to the external blog where of course they cannot be found. do I have to exclude the images from redirection? how can I do that?
benoka
 
Posts: 23
Joined: Fri Jun 19, 2009 9:23 am

Postby benoka » Tue Oct 27, 2009 1:13 am

about the errordocument: i just tested it on another computer where the connection is a bit slower and could actually capture the fact that the error document routing goes correctly to the document i set on the external blog, but it seems the blog "realizes" that it's an error and redirects it to its own error page.
benoka
 
Posts: 23
Joined: Fri Jun 19, 2009 9:23 am

Postby richardk » Tue Oct 27, 2009 11:39 am

yes, their document roots are the ones I setup for them when I add them to my account (exactly as in your example); subdomain document roots can be setup exactly the same way. my main folder I created is called websites and I created subfolders here for all my domains and subdomains separately.

Then a .htaccess file in ./example.com will only affect example.com and not other domains or sub domains. That's probably why it didn't affect other domains.

error page = i meant 'ErrorDocument 404' - i put this line at the very top of the .htaccess file, so i guessed it will execute before going to the blog. I realized i set it up to go to the root ('/') so of course it was passed over to the blog and displayed the blog's error page. I now replaced that with the exact URI of the blog, but it still displays the blog's error page, however what I would like to have is to simply go to the blog's main page, no error document needed.

...

about the errordocument: i just tested it on another computer where the connection is a bit slower and could actually capture the fact that the error document routing goes correctly to the document i set on the external blog, but it seems the blog "realizes" that it's an error and redirects it to its own error page.

Your server doesn't know it will be a 404 on the blog server. The redirect redirects all requests to the blog server with the original path, then the blog server works out if it is a 404.

Also, depending on the blog script, it might be the blog script and not the blog server that displays the 404 page. If it's content from a database Apache (or whatever server) won't know if it's a 404 or not.

By the way, I setup an error page at the blog and tried to setup .htaccess to send 404 requests there but it simply sends the requested URL to the redirected blog like this: somthing.blog.com/[wrongfilename] and displays the blog's standard error message instead of the one I set in .htaccess. Does it mean that the only way to setup an errordocument is if the document is placed on my server? i cannot send those to a specific page on the external blog?

Is it an Apache server? Can you use any directives (for example, Redirect) in a .htaccess file on that server?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby benoka » Tue Oct 27, 2009 1:27 pm

Is it an Apache server? Can you use any directives (for example, Redirect) in a .htaccess file on that server?

yes, Apache works on my hosting server perfectly.

i still don't understand why can't I just send anything that's errorring on my server to one main URL (external blog or whatever).

do you have an answer to the part where I cannot link pictures located under the domain i redirected to the blog? can I setup exceptions for these pictures so that they get through?
benoka
 
Posts: 23
Joined: Fri Jun 19, 2009 9:23 am

Postby richardk » Wed Oct 28, 2009 11:09 am

i still don't understand why can't I just send anything that's errorring on my server to one main URL (external blog or whatever).

Part of it is because there are no 404 errors on the example.com server, just redirects.

What blog script are you using?
Does it use mod_rewrite?

do you have an answer to the part where I cannot link pictures located under the domain i redirected to the blog? can I setup exceptions for these pictures so that they get through?

Oh yeah. Those requests get redirected to the blog server like all example.com requests. Instead of the current redirect, try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule !^images(/.*)?$ http://blog.example.org%{REQUEST_URI} [R=301,L]

It should not (!) redirect requests to /images.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby benoka » Wed Oct 28, 2009 11:59 am

What blog script are you using?
Does it use mod_rewrite?

I don't know, does Blogger (*.blogspot.com blogs) use it?

your code for the images works perfectly, thank you for that!
benoka
 
Posts: 23
Joined: Fri Jun 19, 2009 9:23 am

Postby richardk » Fri Oct 30, 2009 11:06 am

You don't have any control of the Blogger server (you can't upload .htaccess files, can you?) so you can't catch 404 errors.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron