Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

mod_rewrite one rule works, second doesn't

Posted on 2006-03-29
2
Medium Priority
?
271 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
0
Comment
Question by:td234
2 Comments
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 16327963
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
 
LVL 2

Author Comment

by:td234
ID: 16331974
Excellent. That I had deduiced that and tried that, but got it to work from your example.

Thank you.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question