Forum Moderators: phranque
We already run a rule on our main domain name as follow :
RewriteCond %{HTTP_HOST}www.mydomain.com [NC]
RewriteRule ^(.*)/(.*).html /main/www.mydomain.com/$1.php?p=$2[L]
We have a new addon domain www.domain1.com point to /www/domain1/, and have added a new rule :
RewriteCond %{HTTP_HOST}www.mydomain.com [NC]
RewriteRule ^(.*)/(.*).html /main/www.mydomain.com/$1.php?p=$2[L]
RewriteCond %{HTTP_HOST}www.domain1.com [NC]
RewriteRule ^(.*)/(.*).html /main/www.domain1.com/$1.php?p=$2[L]
but, it doesn't work :-(. Could anyone highlight what's going wrong here?
Sorry, here we are with the spaces.
RewriteCond %{HTTP_HOST} www.mydomain.com [NC]
RewriteRule ^(.*)/(.*).html /main/www.mydomain.com/$1.php?p=$2[L]
RewriteCond %{HTTP_HOST} www.domain1.com [NC]
RewriteRule ^(.*)/(.*).html /main/www.domain1.com/$1.php?p=$2[L]
I have only access to the .htaccess file, and I have put it at the www root. the code is definitely being executed (error page displayed for domain1 when I add the new rules)
RewriteCond %{HTTP_HOST} ^www\.(mydomain¦mydomain1)\.com [NC]
RewriteRule ^([^/]*)/([^.]*)\.html$ /main/www.%1.com/$1.php?p=$2 [L]
The above code should take care of both domains with one ruleset, and testing it may shed some more light on your problem. If the two subdomains map to subdirectories in an identical manner, then it's a mystery why one should work and the other not. I do not propose that you use the code above as a final version, since an uppercase or mixed-case domain will break it due to the fact that you (probably) don't have uppercase/mixed-case-named subdirectories.
Replace the broken vertical pipe "¦" character with a solid pipe before use! (Posting here changes them)
Jim
That's the trouble : it doesn't.
mydomain is my main domain, on which I run the following rule :
RewriteCond %{HTTP_HOST} www.mydomain.com [NC]
RewriteRule ^(.*)/(.*).html /main/www.mydomain.com/$1.php?p=$2[L]
the second one is an add on domain pointing to a sub directory (/domain1/), but the code for this domain is in /main/www.domain1.com/...
Adding the second rule using /main/.... get me in a kind of loop and doesn't work!
Is this statement correct? -- domain1? -- And what code is located there - your .htaccess code? (Sorry, we need to be precise here, because mod_rewrite requires precision.)
> Adding the second rule using /main/.... get me in a kind of loop and doesn't work!
Then you may need to add an exclusion to the rule for each subdirectory, such as:
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com [NC]
RewriteCond %{REQUEST_URI} !^/main/www\.mydomain\.com/
RewriteRule ^([^/]*)/([^.]*)\.html$ /main/www.mydomain.com/$1.php?p=$2 [L]
RewriteCond %{HTTP_HOST} www\.domain1\.com [NC]
RewriteCond %{REQUEST_URI} !^/main/www\.mydomain1\.com/
RewriteRule ^([^/]*)/([^.]*)\.html$ /main/www.domain1.com/$1.php?p=$2 [L]
Below is the exact architecture of the site :
/main/www.mydomain.com/index.php
/main/www.domain1.com/index.php
/domain1/
www.mydomain.com is our main domain and points to the root. We run then some url rewrite on it
example :
www.mydomain.com/index/toto.html
=> /main/www.mydomain.com/index.php?p=toto.html
so far so good.
now www.domain1.com points to /domain1/ (addon domain), and we want to run a similar url rewriting on this domain name :
example :
www.domain1.com/index/toto.html => /main/www.domain1.com/index.php?p=toto.html
Please help :-)!
Okay, I have setup aliases instead of domain addons.
Now domain1 is pointing to the root. But I stillcannot get what I want :
RewriteEngine on
RewriteCond %{HTTP_HOST} www.domain1.com [NC]
RewriteRule ^$ [domain1.com...]
RewriteRule ^(.*)/(.*).html [domain1.com...] [L]
RewriteCond %{HTTP_HOST} www.mydomain.com [NC]
RewriteRule ^$ [mydomain.com...]
RewriteRule ^(.*)/(.*).html [mydomain.com...] [L]
works for domain1, but redirect mydomain to domain1.
If take the two directives the other way round, the opposite happens :
RewriteCond %{HTTP_HOST} www.mydomain.com [NC]
RewriteRule ^$ [mydomain.com...]
RewriteRule ^(.*)/(.*).html [mydomain.com...] [L]
RewriteCond %{HTTP_HOST} www.domain1.com [NC]
RewriteRule ^$ [domain1.com...]
RewriteRule ^(.*)/(.*).html [domain1.com...] [L]
works for mydomain, but redirect domain1 to mydomain.
Just doesn't make sense at all to me. please Heeeelp
The following code may not work (solve your problem), but it is more precise and 'more correct':
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule ^$ http://www.domain1.com/index/rw_1_home.html [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule ^([^/]*)/([^.]+)\.html http://www.domain1.com/main/www.domain1.com/$1.php?p=$2 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com [NC]
RewriteRule ^$ http://www.mydomain.com/index/rw_1_home.html [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com [NC]
RewriteRule ^([^/]*)/([^.]+)\.html http://www.mydomain.com/main/www.mydomain.com/$1.php?p=$2 [R=301,L]
Jim