Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Search Engine Optimization (SEO) (http://www.go4expert.com/forums/seo-forum/)
-   -   .htaccess 301 redirect for subdomains (http://www.go4expert.com/forums/htaccess-301-redirect-subdomains-t872/)

GotWeb? 9Jun2006 04:47

.htaccess 301 redirect for subdomains
 
Hi, I hope I'm asking this in the right forum?

I've been searching for an answer to this problem for 5 days, and hopefully someone here knows the solution.

Firstly, I'd like to provide the information that I too am a programmer, experienced in Perl, PHP, JS, Java, VRML, and a little C++, Python, and Delphi.

I have a domain: example.com
that I've created a full independent subdomain for which does not live under the root folder path of example.com

This is a fully qualified subdomain with it's own dns and it's own file path from root that does not connect to the main domain example.com at all. I created the subdomain in WHM on my server backend.

The subdomain is for example:
subdomain.example.com

Then, under the subdomain.example.com folder path (in CPanel) I created the subs of:
sub1.subdomain.example.com
sub2.subdomain.example.com

Now, the root paths for subdomain.example.com
is: /home/user/subdom/public_html/

The root path for the subs of subdomain.example.com
is: /home/user/subdom/public_html/sub1/
is: /home/user/subdom/public_html/sub2/

These are browser reachable by both www and non-www versions.
Google has issues with this big time.

I've tried redirecting subdomain.example.com
from www to non-www
via .htaccess file located at
/home/user/subdom/public_html/.htaccess
and it works fine and does the redirect from www to non-www

But, it forces the subs to their respective folders Vs being treated as sub.subdomain.example.com

In other words, the subs go to:
subdomain.example.com/sub1/
subdomain.example.com/sub2/

If I put 301 .htaccess redirects in for
subdomain.example.com AND
sub1.subdomain.example.com AND
sub2.subdomain.example.com

into the .htaccess file located at
/home/user/subdom/public_html/.htaccess

it creates an infinite loop

If I place .htaccess 301 redirect for JUST
subdomain.example.com
at: /home/user/subdom/public_html/.htaccess
it redirects www to non-www

then placing the same for the subs located in their respective folders:
/home/user/subdom/public_html/sub1/.htaccess
/home/user/subdom/public_html/sub2/.htaccess

it redirects the sub.subdomains from www to non-www
BUT breaks the www to non-www redirect for
subdomain.example.com

Does anyone have any idea how the heck this is supposed to be done? Quite honestly, I'm going out of my mind trying to find the answer.

At help would be very greatly appreciated!

Thanks!

Also, I like this forum and plan to stick around. I'm a good programmer and maybe I can help someone else when they need answers, too? :)

shabbir 9Jun2006 04:57

Re: .htaccess 301 redirect for subdomains
 
Can you let us have the content of the .htaccess file you are using for redirecting it from www to non-www version.

GotWeb? 9Jun2006 05:10

Re: .htaccess 301 redirect for subdomains
 
Sure, I'm using this code:
Code:

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC]
RewriteRule (.*) http://subdomain.example.com/$1 [R=301,L]


shabbir 9Jun2006 05:15

Re: .htaccess 301 redirect for subdomains
 
Just try with hard coded www rather than ^.

What I meant is
RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC]
means redirect starting with anything

try changing to
Code:

RewriteCond %{HTTP_HOST} www.subdomain.example.com$ [NC]
RewriteRule (.*) http://subdomain.example.com/ [R=301,L]


GotWeb? 9Jun2006 05:32

Re: .htaccess 301 redirect for subdomains
 
OK, tried it and it's the same problem.

Putting the codes exactly as you have in the .htaccess file located at:
/home/user/subdom/public_html/.htaccess
redirects www to non-www for
subdomain.example.com

If you put a second condition in that same .htaccess file to handle the www to non-www redirect for the sub.subdomains -- it creates an infinite loop

Remove the second condition from the root .htaccess file and place it instead inside the .htaccess file for the sub.subdomain at:
/home/user/subdom/public_html/sub1/.htaccess
does make the redirect from www to non-www work for
sub1.subdomain.example.com

BUT breaks the redirect for www to non-www of
subdomain.example.com
which uses the .htaccess file at:
/home/user/subdom/public_html/.htaccess

Any ideas? Is this even possible to do, I wonder?

shabbir 9Jun2006 11:17

Re: .htaccess 301 redirect for subdomains
 
If I am getting you correctly all you need is redirect everything to the non-www version. Correct me if I am wrong.

Try this out
To go from the non 'www' to 'www' use this code:
Code:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

To go from the 'www' to non 'www' use this code:
Code:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST}//s%{HTTPS} ^www\.(.*)//((s)on|s.*)$ [NC]
RewriteRule ^ http%3://%1%{REQUEST_URI} [L,R=301]


Alex TJ 13Oct2006 00:12

Re: .htaccess 301 redirect for subdomains
 
Hi Gotweb,

Could you please let us know if that suggestion worked for you ok as I have exactly the same problem with non-www to www for subdomains.

Thanks, and look forward to seeing you guys around the forum.
Alex

shabbir 13Oct2006 10:03

Re: .htaccess 301 redirect for subdomains
 
From non www to www is working on Go4Expert atleast. :)

internetmarketing 29Nov2006 12:25

Re: .htaccess 301 redirect for subdomains
 
Quote:

Originally Posted by shabbir
If I am getting you correctly all you need is redirect everything to the non-www version. Correct me if I am wrong.

Try this out
To go from the non 'www' to 'www' use this code:
Code:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

To go from the 'www' to non 'www' use this code:
Code:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST}//s%{HTTPS} ^www\.(.*)//((s)on|s.*)$ [NC]
RewriteRule ^ http%3://%1%{REQUEST_URI} [L,R=301]


Hi Shabbir...
Above Code doesn't works for me.

I want to redirect my url http://forums.b2binternetmarketingagency.com/ to http://forums.b2binternetmarketingagency.com/forum

I applied this kind of code many times but it show this kind of error.....
when i type address http://forums.b2binternetmarketingagency.com it shows like below...
http://forums.b2binternetmarketingag...um/forum/forum........................ and so on.

Please help me how can i resolve this problem.
:confused:

shabbir 30Nov2006 10:54

Re: .htaccess 301 redirect for subdomains
 
The above should work for www to non www and vice versa but I am not sure on redirecting to a particular folder should work using the above one.


All times are GMT +5.5. The time now is 22:39.