Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Can I 301 Redirect Subdomains Using .htaccess 1

Status
Not open for further replies.

tyhand

Programmer
Jul 3, 2002
186
US
Hi all,

I would like to do a 301 redirect for a few subdomains on my host.

Basically, I want Sub.Domain.com to go to
I've tried the following but it doesn't work:
redirect 301 sub.domain.com
Anyone know how to do this?

BTW, I don't know if the subdomains are "real" subdomains -- whatever that means. They are however subdomains in one of those hosting accounts that allows hosting of multiple domains under one account.

In this kind of setup, you can basically have domain2.com and domain3.com under the same account as domain1.com.

They call this feature "Add-On" domains. And whenever you want to "add on" more domains, it automatically does it for you. It's just that you can also get to the sites by going to, for example, OR subdomain.Domain1.com. Hence the reason why I want the 301 redirect.

Thanks for the help. Peace!
 
The second arg (sub.domain.com) in redirect is a PATH not a host name. And I don't think it can be a regular expression.

So try this:

RedirectMatch 301 (.*)$
(I haven't tested this, BTW)
 
Hey Bid Dog! (that's elgrandeperro in english)

Thanks for the help.

The code doesn't work, but I'm suspecting it's b/c it's missing the expression for the subdomain.

ie: ^subdomain.*

What do you think?

- Tyhand
 
It would be like
RedirectMatch 301 ^/subdomain(.*)$
But you or your provider must allow FileInfo in your apache config in order to do .htaccess. Something that might not be allowed.
 
Hey,

Thanks for the continued help.

Actually, I'm trying to get to redirect to
As far as where I'm putting the HTACCESS File -- I'm putting it in the root of
Don't know about FileInfo, but I've been able to utilize .htaccess files on the server with no problems before.
 
yeah, you can't use REDIRECT directive for that because REDIRECT is for URL paths, it doesn't know about the host part of the URL. You can use REWRITE directives.

But you can put the .htaccess in the subdomain directory, so as long as you don't have a path like /subdomain/subdomin it will match and trigger.

So in /subodomain you would have:

RedirectMatch 301 ^subdomain(.*)$
So as long as you don't have it won't match.
 
Thanks again for all the help.
Have a star!

- Tyhand
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top