Forum Moderators: phranque

Message Too Old, No Replies

redirect subdomain problem

         

rruppel

1:32 pm on May 19, 2009 (gmt 0)

10+ Year Member



Hi all,

I have two domains hosted in my account, both pointing to the root of my site

I have successfully added subdomains to my main domain, in resume, what I have to do is:

1 - add an entry to dns table pointing the subdomain.maindomain.com to the host ip

2 - change my .htaccess adding:

RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.domain\.com$ [NC]
RewriteRule ^/?$ [newurl.com...] [L,R]

that's just fine for the main domain, but for the "additional domain", it just doesnt work

the problem, i think, is that the additional domain is already pointing to a folder inside the main domain, with this:

RewriteCond %{HTTP_HOST} ^(www.)?newdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/newdomain.com/
RewriteRule ^(.*)$ /newdomain.com/$1

RewriteCond %{HTTP_HOST} ^(www.)?newdomain.com$ [NC]
RewriteRule ^(/)?$ newdomain.com/ [L]

so, when I try to add:

RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.newdomain\.com$ [NC]
RewriteRule ^/?$ [newurl2.com...] [L,R]

this just doesnt work... I dont know why :(

I've tryed changing the order of the rules but it didnt work

I just dont know what to do... unfortunately its a shared hosting... so I think it would be dificult to turn the rewritelog on

i woul appreciate any help

thanks in advance

ps: sorry if my english isnt good, its not my natural language

jdMorgan

6:10 pm on May 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why are you redirecting to a new URL instead of doing internal rewrites to simply 'connect' the (sub)domains to the proper new directories and filepaths?

What are you trying to accomplish here?

Note that unless you use the [L] flag on all of your rules, then multiple rules may be applied to some requests, and that is not likely to be what you want to do...

Jim

rruppel

9:51 pm on May 19, 2009 (gmt 0)

10+ Year Member



well,

I wanted to redirect the users from: photos.mynewdomain.com to my picasa account (to have a nice url for my picasa album :D)

its a fair enough requirement =)

and I cant do this direct from my dns table

one option would be an internal rewrite to a page in php that redirects to my picasa album, but if I can do this directly through the .htaccess I would prefer (it would avoid me to create a php file)

thanks for the help

jdMorgan

1:38 am on May 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A rewrite to a script that does a redirect is still a redirect, though.

It was not clear that the content was hosted on an 'outside' server. So yes, the requirement is 'fair,' but the question needed to be asked because many if not most of our members are initially confused between external redirects and internal rewrites, and so implement many unnecessary external redirects.

I should point out, though, that if you have server config access, this might be a perfect application to use a reverse proxy... Host images on Picassa, but show your own site's domain in the visitor's address bar.

But the answer to your oringal question is this: If your new add-on domain points directly to a subdirectory in your account space, then you'll need to reproduce the redirect code in an /htaccess file in that subdirectory; Code in the 'main site's' .htaccess will not be applied to the add-on domain.

Jim

rruppel

9:09 am on May 20, 2009 (gmt 0)

10+ Year Member



hi jdMorgan,

thanks for the answer

unfortunately I dont have server config access, so I have to do it through the .htaccess

what do you mean by: "if your new add-on domain points directly to a subdirectory in your account space"?

if I understood correctly, this "points to" would be an apache server configuration, and then the answer is: no, my add-on domain points to the root of my account space (just like the main domain)

what I've done:

I added this lines to the .htaccess of the root directory:

RewriteCond %{HTTP_HOST} ^(www.)?newdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/newdomain.com/
RewriteRule ^(.*)$ /newdomain.com/$1

RewriteCond %{HTTP_HOST} ^(www.)?newdomain.com$ [NC]
RewriteRule ^(/)?$ newdomain.com/ [L]

to redirect my new domain to a specific folder (in this case, /newdomain.com/

I tryed adding this lines:

RewriteCond %{HTTP_HOST} ^(www.)?sub\.newdomain\.com$ [NC]
RewriteRule ^/?$ [picasaweb.google.com...] [L,R]

I tryed this in the root directory and in the subdirectory /newdomain.com/, but both didnt work

what I find strange is: the same lines work to the main domain

is something wrong with my .htaccess or maybe its a server config issue?

thanks again for the help

jdMorgan

12:50 pm on May 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure the rue are in this order:

RewriteCond %{HTTP_HOST} ^(ww[b]w\.)[/b]?sub\.newdomain\.com$ [NC]
RewriteRule ^/?$ http://picasaweb.google.com/myaccount/ [L,R]
#
RewriteCond %{HTTP_HOST} ^(www.)?newdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/newdomai[b]n\.c[/b]om/
RewriteRule ^(.*)$ /newdomain.com/$1 [b][L][/b]

also also note the bolded corrections.

In general, put external redirects first, in order from most-specific pattern (fewest URLs affected) to least-specific pattern (most URLs affected), followed by internal rewrites, again in order from most-specific pattern to least.

If this does not correct the problem, try adding

 RewriteOptions Inherit 

to one or both of your htaccess files.

Jim