Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite issue

Need a little help :)

         

rykorq

2:00 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



I've been going through the mod_rewrite text on apache and screening through different areas, but I'm still not finding a way to make this situation work and I know it can. I've got four domains that I'm trying to get mod_rewrite to work correctly with and I'm having trouble with the engine, as everyone else seems to. What I've got is an Ensim appliance running on a Linux box, and I've got a main domain of www.abc.com, with three domains aliased to it of www.ccc.net, www.cc.net, and www.ddd.com. I want ccc.net to go to the /ccc/$1 directory, cc.net to go to the same directory, and ddd.com to go to the /ddd/$1 directory while leaving abc.com to go to the /html directory.

I coded the mod_rewrite as follows:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.ccc\.net$
RewriteRule ^(.*)$ /ccc/$1 [C]
RewriteCond %(HTTP_HOST) ^www\.cc\.net$
RewriteRule ^(.*)$ /ccc/$1 [C]
RewriteCond %(HTTP_HOST) ^www\.ddd\.com$
RewriteRule ^(.*)$ /ddd/$1 [L]

What happens is that the first link works. www.ccc.net goes to the right directory and displays correctly. However none of the other portions seem to be executed. I tried adding the chain directive in at the end, but still nothing, so I figured I'd see if anyone could shed some light on the topic here.

Thanks,
George

Caterham

3:36 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Why are you chaining the rules at all? The rule following the rule with the C-Flag will only be executed if the rule applies, e.g. your first rule,
RewriteCond %{HTTP_HOST} ^www\.ccc\.net$
RewriteRule ^(.*)$ /ccc/$1 [C]
must apply that
RewriteCond %(HTTP_HOST) ^www\.cc\.net$
RewriteRule ^(.*)$ /ccc/$1 [C] would be executed if the RW-condition matches.

But this would be impossible because the host doesn't change.

You are using parenthesis () instead of braces {} in two conditions.

May be this helps:

RewriteEngine On
# prevent looping in per-dir context
RewriteRule ^(ccc¦ddd)/ - [L]
RewriteCond %{HTTP_HOST} ^www\.(ccc¦cc)\.net
RewriteRule ^(.*)$ /ccc/$1 [L]
RewriteCond %{HTTP_HOST} ^www\.ddd\.com
RewriteRule ^(.*)$ /ddd/$1 [L]

Change the ¦ into a 'logical or' from your keyboard; the character is changed by the forums software.

rykorq

4:10 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Thank you for the fresh eyes. I had the Chains in there because I was at a loss as to why it wasn't working. Completely had missed that I'd mistakenly substituted ( for { on the HTTP_HOST commands. Works like a charm now.

Much obliged,
George