Forum Moderators: phranque

Message Too Old, No Replies

htaccess subdomain redirection to external site

         

omoutop

11:32 am on Dec 5, 2011 (gmt 0)

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



I was wondering if the following scenario is possible using htaccess rules. I want one subdomain to be redirected to another url.
I have contact the server admin to add the "test" subdomain to "example.com" domain. The main domain has no other subdomains.

What rule must i put in htaccess to do achieve: [test.example.com...] to be redirected to [something-else.com....]

NOTE: www.something-else.com is a complicated url (200 chars length)

omoutop

2:27 pm on Dec 5, 2011 (gmt 0)

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



update:

I used the following rule, but no results. The scren remains white, no erros. The rest of the site works ok.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ example.com/redir.php [R=301,NC,L]

redir.php has a php redirection to the actuall url i want to use. I thought to set it up this way, since the taret url is complicated (something like: [somdomain.com...]

g1smd

7:55 pm on Dec 5, 2011 (gmt 0)

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



You should rewrite not redirect requests to the PHP script.

You're asking for trouble by using a double redirect, a redirection chain, as you have it now.

lucy24

10:45 pm on Dec 5, 2011 (gmt 0)

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



Obvious starter question: Where is the .htaccess file located? It needs to be in a physical directory that's either above or at the top level of the test.example.com directory. For that matter, where is the subdomain physically located? In a directory inside the main example.com, in a directory parallel to example.com, or somewhere else entirely? I stress physical location: no relation to URL.

The target

example.com/redir.php [R=301,NC,L]

is precarious because you're redirecting without giving the full protocol and domain name, without even a leading slash. Your host may have its own rules about how this situation gets handled.

White screen, no errors means you've been taken to a page that exists but has no visible content. What does your browser's address bar say?

omoutop

7:56 am on Dec 6, 2011 (gmt 0)

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




Options +FollowSymLinks
RewriteEngine on
RewriteOptions inherit
RewriteBase /

RewriteCond %{HTTP_HOST} ^test.example1.com$ [NC]
RewriteRule ^(.*)$ http://www.example1.com/redir.php [L]

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


The htaccess file is located to example1.com root directory.
I have no physical access to test subdirectory, although i know it exists - ping to that url shows me the IP of example1.com

Typing test.example1.com to the browser's address bar has no effect. White screen, no redirection, no nothing. If some page exists there, i know not.

g1smd

8:49 am on Dec 6, 2011 (gmt 0)

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



The first rule issues a 302 redirect to the PHP script, and the PHP script issues a second redirect.

You should make the first redirect into an internal rewrite to avoid a "chain".

omoutop

9:59 am on Dec 6, 2011 (gmt 0)

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



g1smd it doesn't work even if i put the full url in ther redirection


RewriteCond %{HTTP_HOST} ^test.example1.com$ [NC]
RewriteRule ^(.*)$ https://www.google.com/a/monacosuitesboracay.com/ServiceLogin?service=mail&passive=true&rm=false&continue=http://mail.google.com/a/monacosuitesboracay.com/&ltmpl=default&ltmplcache=2 [L]


or

RewriteRule ^(.*)$ redir.php [L]


or

RewriteRule ^(.*)$ /redir.php [L]


or

RewriteRule ^(.*)$ http://www.example.com/redir.php [L]

lucy24

1:44 pm on Dec 6, 2011 (gmt 0)

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



Typing test.example1.com to the browser's address bar has no effect. White screen, no redirection, no nothing. If some page exists there, i know not.

Is there anything "behind" the white screen, or is the html source completely empty? You can upload an empty page and it will show up just fine in your browser as a blank screen (I just tried it to double-check). But if there is nothing at that location, you'll get an error message.

The htaccess file is located to example1.com root directory.
I have no physical access to test subdirectory, although i know it exists - ping to that url shows me the IP of example1.com

Oops, wait, am I misunderstanding something here? If you don't have access to the directory that "test" lives in, you can't write htaccess rules for it. htaccess goes by where a file physically lives, not by its URL. (I know this by direct painful experience, because I used to have one directory in my domain that was aliased from my son's userspace. Took me ages to figure out why robots were running rampant in that one directory when I'd blocked them everywhere else.)

omoutop

6:55 am on Dec 7, 2011 (gmt 0)

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



i see - so in other words i must contact support to open ftp access to test subdomain and put htaccess there.
thanks Lucy

omoutop

1:03 pm on Dec 7, 2011 (gmt 0)

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



after gaining ftp access and uploading the htacccess there, it works. Thanks Lucy