We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

mod_rewrite one rule works, second doesn't

td234
td234 asked
on
Medium Priority
285 Views
Last Modified: 2012-08-13
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
Comment
Watch Question

Top Expert 2008
Commented:
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]

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Excellent. That I had deduiced that and tried that, but got it to work from your example.

Thank you.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.