Forum Moderators: phranque

Message Too Old, No Replies

How to prevent multiple domain folder acess using .htaccess

Want to stop access to one domain from another

         

palsforpals

10:06 pm on Aug 20, 2007 (gmt 0)

10+ Year Member



I have a single webhosting account and have 2 domains on it. Suppose I have domain1.com and domain2.com then I have domain1.com mapped at the hosting's root folder and domain2.com mapped to the /domain2 folder. Everything works fine when I access the domains i.e. www.domain2.com opens the /domain2/index.html page while www.domain1.com opens the /index.html page

But my issue is that when any[one] opens www.domain1.com/domain2/index.html... we can see the /domain2/index.html page which I wish to restrict. I want to keep the 2 websites completely separated and dont want to allow users to see domain2 from domain1 and vice versa. Please help!

Sorry if this question has been asked before, but I havent been able to figure out how to use .htacess file yet, so would be glad if some[one] could explain how the required configuration is achieved.

[edited by: jdMorgan at 12:59 am (utc) on Aug. 21, 2007]
[edit reason] English only, no 'L33T' please. [/edit]

g1smd

10:28 pm on Aug 20, 2007 (gmt 0)

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



You need some conditional redirects to stop this.

If "this" is requested, go "there" for the content.

This is a common question. Check the threads here for the last week or so.

Try modifying some example code from one of those threads, and then post back here with what you have done and what problems you are having.

jdMorgan

1:02 am on Aug 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One example thread here [webmasterworld.com].

Jim

palsforpals

7:54 pm on Aug 21, 2007 (gmt 0)

10+ Year Member



I have gone through a lot of posts, but then they all seem to be about redirecting rather than blocking access. Like I mentioned earlier, I wish to block access to the path www.domain1.com/domain2, because I want to separate domain1 and domain2. So if the user/crawler wants to see domain2 he has to go only through www.domain2.com

g1smd

8:20 pm on Aug 21, 2007 (gmt 0)

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



Yes, you redirect domain.com/folder to www.domain2.com for all folders and files.

Then only www.domain2.com can deliver content, and only www.domain2.com can be indexed.

You could simply block access using [F] but that hardly seems necessary.

palsforpals

8:29 pm on Aug 21, 2007 (gmt 0)

10+ Year Member



Mayb Im unable to communicate the kind of configuration I want to perform. If the user has typed www.domain1.com/domain2 and is redirected to www.domain2.com, the user knows that domain1.com and domain2.com are related and domain2 is a folder in domain1's hosting...

So I dont want the user/crawler to understand that both of these domain are related to each other. Got my point? Thats the reason I want to do a block on the folder, when accessing from www.domain1.com

What is [F]? and how to use it? Could please help me out with some examples?

g1smd

8:49 pm on Aug 21, 2007 (gmt 0)

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



They will already know they are related.

They will have the same IP address.

g1smd

8:56 pm on Aug 21, 2007 (gmt 0)

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




RewriteRule someurl - [F]

jdMorgan

2:08 am on Aug 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To be fair, it wasn't clear you wanted to deny access or make it seem that the domains were unrelated. Most Webmasters are trying to fix problems similar to this as part of cleaning up domain and URL-path canonicalization problems.

If the goal is to "seem unrelated," then a 403-Forbidden response would be somewhat "out of character" for a "normal" server. And especially if that were the only circumstance under which the server returned a 403.

I'd recommend rewriting the subfolder request to a non-existent filepath, even literally like this:


# if domain1.com or www.domain1.com
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com
# rewrite /domain2/<anything> to nonexistent filepath
RewriteRule ^domain2/ /file-which-does-not-exist.html [L]

Rewriting to a known-nonexistent file will trigger the server's default 404-Not Found missing page hander. It will have no effect on "domain2" requests.

The above assumes that you already have other working mod_rewrite rules in the file. If not, some additional "setup" is required.

Jim

palsforpals

9:52 am on Aug 22, 2007 (gmt 0)

10+ Year Member




# Enable Symbolic Links
Options -Indexes +FollowSymLinks

# Enable Basic Rewriting
RewriteEngine on

# cache images and flash content for one month
<FilesMatch ".(flv¦gif¦jpg¦jpeg¦png¦ico¦swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

# cache text and css files for one week
<FilesMatch ".(css¦pdf¦txt)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>

# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

# if domain1.com or www.domain1.com
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com
# rewrite /domain2/<anything> to nonexistent filepath
RewriteRule ^domain2/file-which-does-not-exist.html [L]

This is what my .htaccess file looks like... Im still able to view domain2 from www.domain1.com/domain2

Please help!

jdMorgan

3:56 pm on Aug 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see a rule that rewrites requests for domain2.com to its /domain2 subdirectory, so I assume that you've used a "Control Panel" to set up domain2 as an "add-on domain." If this is the case, then your top-level .htaccess won't be executed for any requests to domain2's filespace.

So, you may need to move the rule into .htaccess in domain2's subdirectory, and modify it to work in that location:


# Enable Symbolic Links
Options -Indexes +FollowSymLinks
#
# Enable Basic Rewriting
RewriteEngine on
#
# if requested via domain1.com or www.domain1.com
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com
# rewrite /domain2/<anything> to nonexistent filepath
RewriteRule .* /file-which-does-not-exist.html [L]

Duplicate the cache-control and access control directives you need in domain2's .htaccess as well.

Jim

palsforpals

8:46 pm on Aug 22, 2007 (gmt 0)

10+ Year Member



Thanks a lot Jim. You guessed it right that the mapping of domain to the folders was done from the hosting CP hence wasnt in the .htaccess.

Anyways, I think this solution of showing a file not found page is perfectly suiting the need and thanks a lot for all your support. It is working perfectly when I add the .htaccess to the subdirectory named domain2.

Thanks again for your support and co-operation!