Forum Moderators: phranque

Message Too Old, No Replies

Multiple domains on one account/folder

         

Ben_Dover

4:03 pm on Dec 20, 2005 (gmt 0)

10+ Year Member



Hi, this is what I want:

domein1.com ---> folder1
domein2.com ----> folder2

It is from one account at the provider so it's all in one www folder.

I had this working on the server but when they switched to a new server it did not worked anymore.

Any ideas what is wrong? (this code worked on the old server)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domein1\.com$ [NC]
RewriteRule!^domein1/.*$ /folder1%{REQUEST_URI} [NC,L]

RewriteCond %{HTTP_HOST} ^(www\.)? domein2\.com$ [NC]
RewriteRule!^ domein2/.*$ /folder2%{REQUEST_URI} [NC,L]

jdMorgan

4:29 pm on Dec 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Three questions:

1) Do any of your other mod_rewrite rules still work?
2) Did the IP address change? If so, did you update the DNS for all domains?
3) Are you sure that your host has configured your account to resolve both domains to your account?

In order to 'deliver' domain requests to your account's filespace, both the DNS and the server have to be configured to recognize the domains. Or maybe mod_rewrite is no longer enabled by default, and you'll need to enable it. Or, your host has dropped the "ServerName" or "ServerAlias" directives related to your alternate domains.

The only thing I can see wrong with your code is that the domain name should not be end-anchored (with "$"), since a rule so anchored will fail if the client appends a port number, e.g. "http://example.com:80/page" which is perfectly valid, but will not match your pattern. You could use either

^(www\.)?example\.com
-or-
^(www\.)?example\.com(:[0-9]{1,5})?$

depending on how restrictive you want the match to be. There's generally no need to be specific as in the second example, since requests with anything except a port number would not be resolved to your server anyway.

Jim

Ben_Dover

4:59 pm on Dec 20, 2005 (gmt 0)

10+ Year Member



Hi, thanx for the reply.

1) yes, I tried some other stuff and that still worked
2) DNS still working, I have solved the problem now with a PHP script to redirect the domains to the proper folders.
3) yes, all working with the PHP script.

This script is working so mod_rewrite rules are working:

RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com
RewriteRule (.*) [domain2.com...] [L]

But here the php script get's into action.

jdMorgan

7:02 pm on Dec 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you on Apache 1.x?

If so, move the LoadModule directive for PHP to the TOP of the LoadModule list. Modules are processed in reverse order; if you load PHP after mod_rewrite, then it will run before mod_rewrite has a chance to do anything. This is a very common error, both on self-hosted and commercial servers.

Apache 2.x uses a different mechanism to set module priority, so this will not apply.

Jim

Ben_Dover

7:28 pm on Dec 20, 2005 (gmt 0)

10+ Year Member



Hi, according to the providers website it's: Apache 2.0.53
The rewrite in my second post executes before the php code.

Is there another way to make this rewrite?

jdMorgan

3:21 am on Dec 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, here's how I'd write it:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule !^folder1/.*$ /folder1%{REQUEST_URI} [L]
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com [NC]
RewriteRule !^folder2/.*$ /folder2%{REQUEST_URI} [L]

Note that I changed "domain" to "folder" in the RewriteRule, as it must be in order to avoid a rewrite loop.

Jim

Ben_Dover

11:42 am on Dec 21, 2005 (gmt 0)

10+ Year Member



Hi thanx, it is working now.

Next point is hiding the complete url in the status bar.
I will check the forum to see if that is possible.

jdMorgan

4:04 pm on Dec 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Next point is hiding the complete url in the status bar.
> I will check the forum to see if that is possible.

It's not only possible, it is the default behaviour.

If your subdirectory rewrites are being exposed in the browser, then either you have a problem with the order of your rules, a missing [L] flag, or other rules that are interfering with the domain->subdirectory rewrites.

This is the principle difference between a rewrite and a redirect; Rewrites are internal to the server and do not involve the client, while redirects are external and require client participation in accessing the originally-requested content at a new URL (which changes the browser address bar).

So, something else is messing up your rewrites or forcing a redirect *after* those rewrites have been applied.

Jim

chinesebob

1:29 am on Jan 12, 2006 (gmt 0)

10+ Year Member



Where do you actually put this file. This is exactly what I am trying to do.

jdMorgan

1:45 am on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For the purposes of this discussion, the code is assumed to be located in the .htaccess file in the directory where the default site's 'home' page' is (or would be) located. All additional domains and/or subdoamins are then 'pointed' to this directory by the httpd.conf configuration file, and the code is then used to sort them into their respective folders.

Note that if you have access to the the server's httpd.conf file, then setting up additional virtual servers is a far more efficient method -- if the number and name of the extra domains and subdomains is likely to remain relatively static.

Either way, the httpd.conf file will probably need to be edited to 'pass' request for the new domains and/or subdomains to your filespace. So, in many if not most cases, the cooperation of your hosting provider will be needed.

Jim

chinesebob

1:50 am on Jan 12, 2006 (gmt 0)

10+ Year Member



Thanks. Unfortunately it is a hosted server and I don't have access to the httpd.conf file. I can however point multiple domains to the same root directory. My thinking is that this may enable me to host multiple sites on one account.

Thanks

jdMorgan

1:37 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try it and see. I tend to ignore 'control panels', since they often make a mess of things, but it sounds like your control panel can make the required changes to httpd.conf for you. Start with a small test, and build on that if it works.

Jim