Forum Moderators: phranque

Message Too Old, No Replies

How can I redirect all pages of a subdomain to the add-on pages?

How can I redirect all pages of a subdomain to the add-on pages?

         

east2west

7:02 pm on Apr 25, 2012 (gmt 0)

10+ Year Member



Hi there.

Basically , google is listing all subdomain pages of my add-on domain. A common problem i know.

So.......... in the htaccess I added this:


RewriteCond %{HTTP_HOST} ^subdomain.mymainwebsite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.subdomain.mymainwebsite.com$
RewriteRule ^/?$ "http\://www.mymainwebsite.com/" [R=301,L]


This works for the main subdomain, BUT I can "still access" all of the subdomain pages


So (a) this works: [subdomain.ADDONMAINWEBSITEIUSE.com ] ----> redirects successfully to----> [ADDONMAINWEBSITEIUSE.com ]

BUT (b) I can still access e.g. http ://www.subdomain.ADDONMAINWEBSITEIUSE.com/about



Google has listed hundreds of these above subdomain "pages"

So my question is... is there any 'code' that i can add in my htaccess, which redirects "ALL" the subdomain "pages" which have unfortunately been listed in google?


So I need http ://www.subdomain.ADDONMAINWEBSITEIUSE.com/about (faq/history/contact/links, and hundreds more pages)

to goto

http ://www.ADDONMAINWEBSITEIUSE.com/about (faq/history/contact/links, and hundreds more pages

lucy24

10:05 pm on Apr 25, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you mean that you have no subdomains, so you want everything to redirect to the main domain? That's a simple RewriteRule which you should already have in place for all-around canonicalizing. Quick search of this Forum should turn up examples without number, because it's a question that has come up every day since the dawn of time. Or, at least, the dawn of WebmasterWorld. Same difference ;)

But before you start redirecting, you need to figure out where all these bogus URLs are coming from so you can stop the flood. Did you formerly have subdomains? Or is your site set up to allow wild-card subdomains, so g### can simply make something up and see what happens? (They have been known to do this with other aspects of a request.)

g1smd

11:32 pm on Apr 25, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your rule RegEx pattern of
^/?$
means the redirect can happen only for
example.com/
with one slash and
example.com//
with two slashes.

Adjust the pattern to match more URLs, not just single and double slash.

east2west

11:02 am on Apr 26, 2012 (gmt 0)

10+ Year Member



Thanks for your reply guys, but i got it sorted out. I had to use a wildcard redirect.


let me elaborate for people who intend on using bluehost. i'm on bluehost (sigh). i have one main domain, which is called the hosting domain, basically, it's "any old domain" which you need to register with bluehost in order to open a bluehost account. So basically with bluehost, this domain will be your public_html folder. i chose www. blahblahblah.com to open a bluehost account right? But I "never" use this domain. This is my public html folder, the holding domain for my entire bluehost account. So to be safe, I use ADD-ONS for all my websites (as was told many years ago using the root public html for a website was unsafe)


Unfortunately, when i create any add-on, bluehost also create a silly subdomain too, meaning: any 'add-ons' i use, will also be accessed at: www. blahblahblah.ADDON.com

Double unfortunately, google have now listed all pages in www. blahblahblah.ADDON.com "AND" www. ADDON.com

So.......... to solve this, in the htaccess I added the code i mentioned
Now (a) blahblahblah.ADDON.COM redirects to ADDON.com which was great!

BUT........... I could "still access" www. blahblahblah.ADDON.com/about (and hundreds of other pages, e.g. about/contact/faq/article1/article2)


Bluehost support guy said: There is a way to redirect all of your links without adding each one into the htaccess. You will want to use a "Wildcard Redirect". But now it looks like that I will have to do this for 'every single add-on i create' to stop them being accessed at the bloody subdomain (www. blahblahblah.ADDON.com) which will lead to www. blahblahblah.ADDON.com being listed at google.


I use bluehost, because their cheap. But this thing is now a problem. Also, there is now the problem of hundreds of www. blahblahblah.ADDON.com urls now listed in google. How on earth do i remove these? or shall i just leave them in google, as now their using the wildcard direct, they should drop out of google at some point i guess(?)

g1smd

6:29 pm on Apr 26, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As I explained above, the ^/?$ pattern in your rule works only for / and // requests.

Change this pattern to something else in order to make it work for other paths and files on your sites. It is likely that (.*) will be what you need.

east2west

11:44 am on Apr 27, 2012 (gmt 0)

10+ Year Member



like i said, it's been sorted out now cheers ;)