Forum Moderators: phranque

Message Too Old, No Replies

Redirecting external access to subdomain

         

Zanza

12:09 am on Nov 20, 2009 (gmt 0)

10+ Year Member



Hello jdMorgan, I think you probably know the answer to my question, as it seems pretty easy, but I really can't find the solution.

My .htaccess needs this, as I can't succesfully get it: it goes in loop when I type the NEWADRESS.com....:

- I have my website: [MYDOMAIN.com...]

- In it, there are some subdomains, like: [SUBDOMAIN.MYDOMAIN.com...]

- I have bought a new adress: [NEWADRESS.com...]

My task is that every request coming to this NEWADRESS, will point directly into SUBDOMAIN.MYDOMAIN.com

In my admin control paneI, I can do this task, but only for pointing to the root of MYDOMAIN.COM, not to a subdomain of my choice in it.

-----------

And one more small request: I have set-up the mod for preventing hotlinking which works perfectly, but I have another issue:

- I don't want that people link directly to any particular html files located in some subfolders, but instead get directly to the index file of my choice

For example, if people from a forum are trying to links directly to:
[MYDOMAIN.com...]

They would automatically come to:
[MYDOMAIN.com...]

----------

Here's my htaccess file

# STRONG HTACCESS PROTECTION
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>

# AUTHORIZED DOMAINS TO SHOW IMAGES AND FILES FROM MY DOMAIN
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?MYDOMAIN.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?SUBDOMAIN.MYDOMAIN.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?google.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?webmasterworld.com(/)?.*$ [NC]
RewriteRule \.(jpg¦gif)$ [MYDOMAIN.com...] [R,L]

# REDIRECTING OLD TILDE SUBDOMAINS
RedirectPermanent /~SUB/ [SUB.MYDOMAIN.com...]
RedirectPermanent /~SUB2/ [SUB2.MYDOMAIN.com...]

# EXTERNAL ACCESS REDIRECTION

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?NEWADRESS.com(/)?.*$
RewriteRule .* [SUBDOMAIN.MYDOMAIN.com...] [R=302,L]

Thanks a million time if you can help me to solve these problems

jdMorgan

2:31 am on Nov 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you're checking the wrong server variable:

RewriteCond %{HTTP_HOST} ^(www\.)?NEWADRESS\.com
RewriteRule ^(.*)$ http://SUBDOMAIN.MYDOMAIN.com/$1 [R=301,L]

Jim

Zanza

7:06 am on Nov 20, 2009 (gmt 0)

10+ Year Member



Wow, I can't believe it, it works !

I will tailor it a little, so it will not display SUBDOMAIN.MYDOMAIN.com, but still retain in display NEWADRESS.com.

Thanks a lot you're my hero of the day ;-)

Any clue maybe for my second request ? :oops:

Zanza

10:00 am on Nov 20, 2009 (gmt 0)

10+ Year Member



And one more small request: I have set-up the mod for preventing hotlinking which works perfectly, but I have another issue:

- I don't want that people link directly to any particular html files located in some subfolders, but instead get directly to the index file of my choice

For example, if people from a forum are trying to links directly to:
[MYDOMAIN.com...]

They would automatically come to:
[MYDOMAIN.com...]

----------

jdMorgan

2:11 pm on Nov 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have to be very careful doing that, since HTTP_REFERER is not at all a reliable header. It may be blank or it may be spoofed, and there is no way to tell.

The answer to the problem is to get a *very* good definition of "people coming from a forum" and test that against HTTP_REFERER. If the referrer does not match, serve the requested "anyfiles.html". If the referer does match, then 302-redirect to index.html.

Alternatively, if the HTTP_REFERER is your own site or is blank, then serve the requested resource, and if not, then serve index.html

You'll have to decide which approach more suits your needs.

This method is at best a "50% solution" but it's the best you can do based on looking at the Referer header. A better solution is to have the "authorized referring pages" on your site set a session cookie, and then check for that cookie whenever a restricted resource is requested. If the cookie isn't set, then serve the index page, and steer the visitor to one of the pages that is authorized and sets the cookie. You will also need some way to detect visitors who have cookies disabled, and a help page to tell them how to enable them in the major modern browsers...

If you don't want to get into that level of complexity, then perhaps the "50% solution" using a referrer check will be 'good enough' for you.

Jim