Forum Moderators: phranque

Message Too Old, No Replies

link domain with url rewritten subdirectories

link domain with url rewritten subdirectories

         

filip fireit

7:35 am on Sep 23, 2009 (gmt 0)

10+ Year Member



Hi,
We are developing an application where multiple websites are present on the same server and make use of the same database and CMS scripts.

In a normal situation the websites will be present in subdirectories: e.g: www.thesite.com/userwebsite . "userwebsite" is not a real physical directory, instead it is an url rewrite to a script that shows the correct pages for that site.

The problem comes when a client wants a personal domain name. In this case www.thesite.com/userwebsite/mypage.htm should become www.userwebsite.com/mypage.htm.

Anyone has an idea how this can be done?

Note that it is important that the url shown in the browser always will be www.userwebsite.com/ followed by the page name. Behind the scenes the correct script should still be executed.

Thanks,

Filip

jdMorgan

12:39 pm on Sep 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming that your server has a dedicated IP address, this isn't so much of a problem -- It's actually somewhat easier to take care of canonicalization issues if the users all have their own domains or use subdomains of your domain.

In either case, it's a matter of checking the HTTP_HOST variable in a RewriteCond, and if it's not "www.thesite.com" or "thesite'com" then extract the domain or subdomain, and use it to build the correct filepath or script query string.

Note that you will be much happier (i.e. you'll be less restricted and have far fewer problems) if you map users to /users/username/mypage; The "users" part of the URL-path will immediately and easily identify requests which need to be rewritten and have not already been rewritten to a subdirectory.

This allows you to put any file in your top-level directory without worrying that it will conflict with an existing or future username. Note that my "/users" path is just an example. It could be "/u" or "/usernames" or whatever you like, as long as it's not likely to conflict with a required top-level file or directory name.

To ease canonicalization problems, I'd further suggest that you require each user to either have their own domain name (www.username.com) or their own subdomain (username.example.com) and store their files in two subdirectory structures, say "d_users/" for unique-domain users and "/s_users" for subdomain users. In this way, any direct client request for "/d_dusers/<username>" can be 301-redirected back to "www.<username>.com" and any direct client request for "/s_users/<username>" can be 301-redirected back to "<username>.example.com" to assure that only canonical URLs can be used to directly access the users' account spaces. This helps prevent them (and other curious or malicious persons) from 'poking around' in each others' filespaces, as well as assuring that resources can only be accessed directly by using the canonical URLs for those resources.

In order to ease server administration and allow easy 'sharing' of resources and scripts, you'll want to have a dedicated IP address. In this way, you can assign ("point") as many domains and subdomains as you like to your server, and the only required change will be at the DNS zone file level. If you don't have a dedicated IP address, then you'll likely be constantly fighting the requirements and restrictions imposed by your "control panel."

Jim

filip fireit

1:08 pm on Sep 23, 2009 (gmt 0)

10+ Year Member



Hi Jim,
Thank you very much for your detailed answer. I will test it immediately.
It is good advice to make use of the /users directory.

We are still in development phase and still have to decide which server we will use for the project. But it is indeed a requirement that we can easily add new domains and subdomains.

Filip