Forum Moderators: phranque
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
- 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...]
----------
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