Forum Moderators: phranque

Message Too Old, No Replies

Handling 200 addon domains with one .htaccess file?

without the need of a .htaccess for each addon

         

neomodus

12:06 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



Hello,

We have an account with about 200 addon domains. Each addon domain has its own folder but it is accessed directly like [domain1.com...]

So the directory is something like this:

MainDomain
¦
¦-Domain1
¦ ¦-index.php
¦ ¦-somefile.php
¦-Domain2
¦ ¦-index.php
¦ ¦-somefile.php
¦-index.php
¦-client_display.php

Now, what we want is that our user can enter [domain1.com...] and this request be handled by "client_display.php?client=clientName" (client_display.php is located in the root of the "maindomain") while the address bar still displays [domain1.com...]

This should be the case with all addon domains.

I don't know if its clear what I am asking

I hope some mod_rewrite expert can help

Thanks!

valder

4:37 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



Hi,

I think the following will do the trick:

# This conditional should take what is in between the first and second slashes in the REQUEST_URI. Parantheses means that it will become a variable named %1
RewriteCond %{REQUEST_URI} /([^/]+)/?.* [NC]
# This rule will use the variable from above.
RewriteRule .* /client_display.php?client=%1 [L]

I haven't tested it though, but it's worth a try?

Be aware that this should rewrite any request to subcatalogs under root. If you don't want that to happen, you need extra conditionals, or you could rewrite requests to for instance domain.com/clients/clientName only.

If you still want domain.com/clientName, you must add conditionals like;

RewriteCond %{REQUEST_URI} !^/images [NC]
RewriteCond %{REQUEST_URI} !^/someCatalog [L]

before the RewriteRule. This means that requests to /images will not be rewritten to /client_display.php?clientname=images.

Or you could just place clients under a catalog such as /clients/clientName.
That would make the rule:

RewriteCond %{REQUEST_URI} /clients/([^/]+)/?.* [NC]
RewriteRule .* /client_display.php?client=%1 [L]

Disclaimer: I am still a mod_rewrite newbie, and can't guarantee that this will work :)

-Eivind

[edit: missing flags]

[edited by: valder at 4:46 pm (utc) on Jan. 10, 2005]

valder

4:40 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



Another thing that made me think;
You have 200 domains? Do you have your own server, or is it a shared server?
If you have access to the server configuration file, you should use that instead of .htaccess files.

neomodus

5:36 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



Hey, thanks for your help, but it didn't work :(

It works when it is used with the "MainDomain", but when I use it with the addon domain (e.g [addonDomain.com...] ) I get an Internal server error.

valder

8:02 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



Could you show me the error log entry?

And what do you mean by addonDomain?
Do you mean subdomain, like sub.domain.tld?

valder

8:38 pm on Jan 10, 2005 (gmt 0)

10+ Year Member



I've got another suggestion for you.
(Didn't pay enough attention to what you wrote about the domain structure)

Perhaps this code works:

RewriteCond %{REQUEST_URI} !/client_display\.php.* [NC]
RewriteCond %{REQUEST_URI} /([^/]+)/?.* [NC]
RewriteRule ^.* /path/to/document_root/client_display\.php\?client=%1 [L]

Hope it helped,
-Eivind

valder

2:03 pm on Jan 11, 2005 (gmt 0)

10+ Year Member



I'd like to make an addition to my last post;
In case it's unclear, the /path/to/document_root/ must be the physical path on the server, like /apache/www/user/htdocs/ or similar.