Forum Moderators: phranque

Message Too Old, No Replies

addon domains management

         

carote

4:05 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



Hi,

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?

jdMorgan

4:23 pm on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) Your code is missing many required spaces.
2) If you pointed domain "domain1.com" to subdirectory /www/domain1/, are you sure the mod_rewrite code will be executed? -- i.e., is the code located in the path to that subdirectory? (You didn't say if your code was in .htaccess or in httpd.conf)

Jim

carote

4:46 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



1) Your code is missing many required spaces.
2) If you pointed domain "domain1.com" to subdirectory /www/domain1/, are you sure the mod_rewrite code will be executed? -- i.e., is the code located in the path to that subdirectory? (You didn't say if your code was in .htaccess or in httpd.conf)
Jim
-----------
Hi Jim,

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)

jdMorgan

2:55 am on Jun 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I see nothing wrong. How about combining these rulesets and see what happens...

RewriteCond %{HTTP_HOST} ^www\.(mydomain¦mydomain1)\.com [NC]
RewriteRule ^([^/]*)/([^.]*)\.html$ /main/www.%1.com/$1.php?p=$2 [L]

Note that special characters such as "." need to be escaped in the regex patterns only, and that I replaced ".*" in both cases with a less-ambiguous pattern, "not slash" and "not dot" instead of "any character". This is a performance enhancement only.

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

carote

6:52 am on Jun 2, 2004 (gmt 0)

10+ Year Member



"If the two subdomains map to subdirectories in an identical manner.."

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!

jdMorgan

2:36 pm on Jun 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> 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/...

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]

Jim

carote

5:06 pm on Jun 2, 2004 (gmt 0)

10+ Year Member



It doesn't work Jim.

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 :-)!

jdMorgan

2:15 am on Jun 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The simplest fix I can think of is to set the DNS to point the new domain to the root, just like your main domain.

Jim

carote

8:25 am on Jun 3, 2004 (gmt 0)

10+ Year Member



That what I thought :-(.

Our hosting company (www.linkstream.net, don't go for them!) has spent 1 month just to set this addon. I am a bit scared now to ask them to modify the DNS record again...and I hoped to find an other solution.

Well, here we go. Thank you for your time Jim.

Cheers,
Carote

carote

4:15 pm on Jun 7, 2004 (gmt 0)

10+ Year Member



Sorry (a few typos):

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

jdMorgan

5:23 pm on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A few points:

  • RewriteCond affects only the immediately-following RewriteRule. Therefore, only the first RewriteRule in each of your rulesets is affected by the RewriteCond. You will need to duplicate the RewriteConds for each RewriteRule.

  • Special characters in regular-expressions patterns must be escaped by preceding them with "\". For example,
    "RewriteCond %{HTTP_HOST} www.mydomain.com" [NC] should be "RewriteCond %{HTTP_HOST} www\.mydomain\.com [NC]"
    The characters which must be escaped are .+*?{}()^$¦[]\, and in some cases, -

  • You should use start and end anchors on your patterns, where applicable. For example,
    "RewriteCond %{HTTP_HOST} ^www\.mydomain\.com [NC]". Do not end-anchor domain names when testing %{HTTP_HOST}, since they sometimes have a port number appended.

  • You can make any character or group of characters optional by following them with "?". To define a group, enclose it in parentheses. This method is used below to make the "www." part of your domain names optional in the RewriteConds.

  • Avoid the use of the pattern ".*" -- It is the most ambiguous pattern, and can slow down processing. It is often better to use a forward-looking negative match, such as "any number of characters not a slash", written "[^/]*" instead of ".*".

    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]

    Refs:
    Apache mod_rewrite documentation [httpd.apache.org]
    Apache URL Rewriting Guide [httpd.apache.org]
    Regular Expressions Tutorial [etext.lib.virginia.edu]

    Jim

  •