Forum Moderators: phranque

Message Too Old, No Replies

Rewrite help needed to eliminate virtual host subdomain

Rewrite temporary url given by my virtual host (user.hostsdomain.com)

         

JRMaine

12:37 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



How can I redirect or rewrite my pages in order to prevent my site from being indexed and/or publically accessed as a subdomain of my virtual host?

My own site (www.mydomain.com) should be showing in search engines, and it does somewhat. However, the temporary url given by my virtual host company (username.hostsdomain.com) has replaced my domain in the SERPs. The host's subdomain names were publically exposed during server maintenance, and now the spiders won't let go of them.

Is it possible to rewrite these requests so the pages requested under the hosts url (username.hostsdomain.com) will go out under only my own domain name (www.mydomain.com)?

I only have access to my own site directory, not to the hosts site.

Thanks for any ideas or links to other threads.

jdMorgan

3:32 pm on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does your host allow you to use mod_rewrite?

If so, then this is a simple domain redirection problem.

If not, then the only solution is to use canonical URLs in all links on your pages, so that every link on your site includes the proper domain name, instead of using page-relative or server-relative links.

Jim

JRMaine

5:16 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



Jim,

Thanks for the help. Mod_rewrite is activated (is now used to redirect non-www to www domain).

I didn't realize that rewrite worked across domains (myhost.com to mysite.com). Or are you saying to just use "redirect"?

Thanks,
John

jdMorgan

7:03 pm on Sep 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Domains don't exist inside the server, once the server passes control to your account's filespace. The directives in httpd.conf that 'select' a particular account-related filespace are the last place in the chain of events where domain has any meaning. After that, everything is based on local URL-paths and filenames.

So, if both the temporary domain (actually a subdomain of your host's domain) and your 'real' domain both resolve to your filespace, then you can use mod_rewrite to check the hostname requested by the client, and redirect to the proper domain. This really doesn't mean anything to browsers, but search engines, upon seeing the redirect, should update their URLs to use the correct domain.

As an example:


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

would redirect requests for any resource (page, image, etc.) in username.hostdomain.com to the same resource in www.yourrealdomain.com

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

JRMaine

8:06 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



Jim,

Absolutely beautiful! Works like a charm. Thanks so much for the invaluable help and great links to study. I have several more sites still on this host that can now be repaired too.