Forum Moderators: phranque

Message Too Old, No Replies

Redirect subdomain to main domain mod rewrite

         

arizonax3

8:58 pm on Jan 5, 2011 (gmt 0)

10+ Year Member



Hi Everyone!

Having some issues with a temp subdomain site coming up in search engines. The way my host works is that all addon domains are subdirectories within the main account, and you have to create a subdomain for every new website. Now that the main website is launched, I want the subdomain requests to resolve to the main site.

Trying to use .htaccess mod_rewrite to fix, but all I can find are posts doing the opposite, and I can't figure out how to fix the code to suit my situation... just keep getting 500 errors or it just doesn't work at all.

Need to rewrite all [subdomain.mysite.com...] requests to [mysite.com...]

That's it... if someone can help, I'd be grateful!

jdMorgan

11:45 pm on Jan 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to put a redirect into .htaccess in each test-subdomain's directory.

Either a mod_alias Redirect
 Redirect 301 / http://mysite.com/ 

or a mod_rewrite RewriteRule
 RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L] 


Requests for add-on subdomains do not process the main domain's .htaccess file, so each subdomain-subdirectory must have its own.

Jim

arizonax3

6:06 pm on Jan 6, 2011 (gmt 0)

10+ Year Member



Hi Jim,

Thanks for the response!

I tried the redirect 301, but got a message from the browser, "The webpage at [mysite.org...] has resulted in too many redirects...", although I did notice in the browser that the subdomain was no longer showing, so it did alleviate the subdomain resolution issue?

The second Rewrite rule didn't work for me... the subdomain was still resolving.

The .htaccess file is in the add on website (the subdirectory) directory... if that makes sense. I don't have any directives for my subdomains/add on directories in the main directory/main website.

I'm also using Wordpress which stores the .htaccess file in the root of the subdirectory/add on directory -- maybe there's somewhere else I need to add another .htaccess file?

I got all my other 301 redirects from the old site (ASP based files) to the new Wordpress platform working in this .htaccess file (so I have a lot of 301 line item redirects in there already), but I just can't get the subdomain thing to work right.

Thanks again!