Forum Moderators: phranque
I have something like this:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} www.domain1.pl
RewriteCond %{REQUEST_URI}!index1/
RewriteRule ^(.*)$ index1/$1 [L]
RewriteCond %{HTTP_HOST} www.domain2.pl
RewriteCond %{REQUEST_URI}!index2/
RewriteRule ^(.*)$ index2/$1 [L]
but this change main directory, and i need to load file www.domain1.pl/index1.php or www.domain2.pl/index2.php
thanks a lot.
If I understand your requirements, the following should work. Note the order of the Options and the RewriteEngine directives. The value of %1 in the first RewriteRule is taken from the grouped class (-one¦-two) in the RewriteCond, and this rewrite will accept either www.domain-one.pl or www.domain-two.pl.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain(-one¦-two)\.pl
RewriteRule ^$ /index%1.php [L]
If you also want to allow users to access your site using "http://domain1.pl" (without "www"), then you can modify the above:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain(-one¦-two)\.pl
RewriteRule ^$ /index%2.php [L]
These rewrites illustrate the use of backreferences to variables in the RewriteCond, whereas most simple rewrites use backreferences to variables only in the RewriteRule itself. Apache mod_rewrite documentation [httpd.apache.org]
Note thet you will need to edit the "¦" characters in the above code, and replace them with the "¦" character on your keyboard, usually "SHIFT \".
Jim