Forum Moderators: phranque
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]
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
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.
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
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]
Jim
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
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