Forum Moderators: phranque

Message Too Old, No Replies

example.com 301'd my subdomain

how to 301 to www, but not affect subdomain

         

youfoundjake

4:19 am on Feb 12, 2007 (gmt 0)

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



RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]

That is my current 301.

I just added a subdomain for a different section in the site

customers.example.com
(index.htm redirects to /)

But when I type that into browser, i'm getting redirected to
www.example.com/customers/

How would i fix that?

jdMorgan

1:43 pm on Feb 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> But when I type customers.example.com into browser, i'm getting redirected to www.example.com/customers/
> How would i fix that?

The answer to that depends on exactly what you mean by this:

> I just added a subdomain for a different section in the site

It is very likely that the code you used (or that perhaps your control panel created) when you added the subdomain is responsible for this problem, since the code you are using (as posted above) has nothing to do with subdomain requests.

Jim

youfoundjake

3:33 pm on Feb 12, 2007 (gmt 0)

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



Weird, when I look at the headers,
I type in the address [customers.example.com...] and I get a 301 status, which also then forwards the query to http://www.example.com/customers/ which then returns a status code of 200.
The odd thing is, 2 or 3 months ago, when I was messing around, I was able to create a subdomian and have it accessible using the correct URL. Later today I will play around with it, and see what else I can find out. I am using cpanel for whatever thats worth.

youfoundjake

6:25 pm on Feb 12, 2007 (gmt 0)

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



RewriteCond %{THE_REQUEST} ^.*\/index\.htm?
RewriteRule ^(.*)index\.html?$ http://www.example.com/$1 [R=301,L]

That I believe is where my problem lies..
When i type in [customers.example.com...] my URL stays the same, (plus I think they now have DNS enabled on hosting now)

But anywhoo... the address [customers.example.com...] stays fine yay!

The address [customers...] redirects to
http://www.example.com/customers/

So by looking at the rewrite, would i want it to say?

RewriteCond %{THE_REQUEST} ^.*\/index\.htm?
RewriteRule ^(.*)index\.html?$ ^.example.com/$1 [R=301,L]

jdMorgan

12:22 am on Feb 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, that substitution is invalid. Something like this, perhaps:

RewriteCond %{THE_REQUEST} [^\?]*/index\.html?
RewriteRule ^(([^/]+/)*)index\.html?$ http://%{HTTP_HOST}/$1 [R=301,L]

This redirects index.html or index.htm in any (sub)directory to "/" of that (sub)directory using the currently-requested hostname, whatever it may be.

Jim

youfoundjake

11:41 pm on Feb 13, 2007 (gmt 0)

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



So I put in that change.

customers.example.com works fine
customers.example.com/index.htm gives me a 404, so I'll keep playing around with it.
Thanks Jim

youfoundjake

4:35 am on Feb 15, 2007 (gmt 0)

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



Hey Jim,
what if I put a .htaccess file in the subdomain directory redirecting subdomian.example.com/index.htm to subdomain.example.com/
Do you think that will work?

youfoundjake

3:20 am on Feb 19, 2007 (gmt 0)

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



Looks like adding a .htaccess file the the subdomain directory worked.

I created the .htaccess file in the \customers folder and added the following to it:


RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*\/index\.htm?
RewriteRule ^(.*)index\.html?$ [customers.example.com...] [R=301,L]

And, of course everything 301's perfectly.

My example.com 301's to www.example.com
My www.example.com/index.htm 301's to www.example.com
My customers.example.com/index.htm 301's to customers.example.com

All pages work, no 404's so it was a good day. Since all robots are blocked from \ with the exception of msn, yahoo google, ask and ia_archive, I would imagine that the subdomain should be crawlable as well, but I will put my bot-trap up there as well.

Hope this helps out anyone, thanks for the nudge in the right direction Jim, have a good week.