Forum Moderators: phranque

Message Too Old, No Replies

Hosting a website under a subdirectory

Need help denying access from certain URL

         

cookiemonster

4:54 am on Aug 14, 2012 (gmt 0)

10+ Year Member



This may seem like a silly question for some experts but,


I have a website "example.com" that is hosted in a subfolder of another domain "example2.com" (GoDaddy shared hosting).

So if a user were to go to "example2.com/subfolder/website", it would look the same as just going to example.com.

I want to only allow users to access the site by going straight to example.com, and deny (maybe even 404) access from "example2.com/subfolder/website" to avoid confusion and for security purposes.

I'm assuming this can be done with .htaccess?


Thanks in advance!

Regards,
Michael

phranque

5:17 am on Aug 14, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



yes, you can do either in .htaccess.
you would test for the example2.com hostname and a path that starts with the subfolder and in the RewriteRule you could use either the "[F]" flag (which returns a 403 Forbidden status code) or the "[R=301]" flag (which returns a 301 Moved Permanently status code).

wilderness

6:31 am on Aug 14, 2012 (gmt 0)

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



I have a website "example.com" that is hosted in a subfolder of another domain "example2.com" (GoDaddy shared hosting).

So if a user were to go to "example2.com/subfolder/website", it would look the same as just going to example.com.


I believe you've misunderstood how multiple domains work on shared hosting (or any other type of hosting).

1) your root directory (main user) is actually one directory higher in the path than your primary domain.
2) for a second (or more) domains to be hosted a sub-domain is actually created, rather than a sub-directory.
3) if sub-domain is failing (allowing the path access via the other domain), than you either have an issue with your host or an issue with DNS propagation.
4) It's my opinion that your simply confused over what your seeing in the GoDaddy Control Panel.

My suggestion to you, is use another computer and another IP to determine if your actually able to access VIA HTTP, and NOT the GoDaddy Control Panel.

example2.com/subfolder/website/example.com


FWIW I did some work last year for an org that had a sub-domain via multiple hosting and using GoDaddy last year.
The primary account holder had a dozen domains, and the domain I was working on was an additional sub-domain. Logging in required using the primary users name and password, which is bad judgement on the part of both the primary and secondary users. Somehow, GoDaddy was able to distinguish these different domains in billing.

wilderness

3:30 pm on Aug 14, 2012 (gmt 0)

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



As an afterthought, another way in which you could explore the separate functionality (and files) of both domains is via FTP access.

1) log-in to the example2 site (not the GoDaddy user-root) and see if the example website files are available.
2) log-in to the example site (not the GoDaddy user-root) and see if the example2 files are available

If the files for example.com are duplicated and co-exist
1) one as its own domain
2) and then again in the example2 sub-folders, it's possible that you have yourself duplicated the files in error.

g1smd

3:38 pm on Aug 14, 2012 (gmt 0)

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



Yes it is quite common for example.com to be the main hostname and then the content at
- http://example.org/ to also be found at http://example.com/example.org/ (where .org is a folder name)
- http://example.net/ to also be found at http://example.com/example.net/ (where .net is a folder name)
and so on.

Likewise the content found in subdomains can often also be found in a folder of the same name inside the main site.

This is quite common among the cheaper hosts. The rght way to do it, is to create folders for the other sites above the web root of the main site and not in a public folder within the main site.

And, yes, it is very easy to construct rules that either block access or redirect the user to the right version when the wrong one is requested.

cookiemonster

8:20 pm on Aug 14, 2012 (gmt 0)

10+ Year Member



@phranque, @g1smd: Thank you for your answers! I'll now research how exactly to write the .htaccess file(s) since I'm a newbie.

@wilderness: Thank you for your replies also, but I believe you have misunderstood my problem here. Perhaps someone searching in the future will find your answers helpful!

Cheers to all,
Michael