mod_rewrite one rule works, second doesn't

I am really confused on this one.

Using mod_rewrite on Apache 1.3 for a while. I want to add a new rule and it does not seem to be inheriting a value from teh Rewrite Cond.

   RewriteEngine on
    RewriteCond     %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
    RewriteCond     %{REQUEST_URI} !^/lib/
    RewriteRule     ^/forums/(.*)$ /home/web/public_html/page1.php?country_dir=%1&path=$1 [QSA,L]
    RewriteRule     ^(.*)$ /home/web/public_html/page2.php?country_dir=%1&path=$1 [QSA,L]

My first rule will pass the sub_domain whenI use "%1", but the second one does not. Is there a trick to this? What am I missing?

T
LVL 2
td234Asked:
Who is Participating?
 
caterham_wwwCommented:
You must repeat the condition, because the condition is checked only after the RewriteRule was checked (and matched), so the cond. can apply only to the corresponding rule.

RewriteEngine on
RewriteCond     %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
# that condition seems to be useless. If you're restricting the rule to /forum/, the condition
# will never match against /lib/, because in the rule you already said it must start with /forum/
#RewriteCond     %{REQUEST_URI} !^/lib/
RewriteRule     ^/forums/(.*)$ /home/web/public_html/page1.php?country_dir=%1&path=$1 [QSA,L]
# may be the cond. is for that rule?
RewriteCond     %{REQUEST_URI} !^/lib/
RewriteCond     %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule     ^(.*)$ /home/web/public_html/page2.php?country_dir=%1&path=$1 [QSA,L]
0
 
td234Author Commented:
Excellent. That I had deduiced that and tried that, but got it to work from your example.

Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.