Help with rewrite rule

Topics: User Forum
Sep 5, 2008 at 2:34 PM

I'm a newbie concerning regular expresions :(

I need to transform this URL:

Into this:

I wrote this rule to accomplish this task:

RewriteRule news/(.*)/(.*)/$ /Clients/ClientName/web/news.php?$1=$2

¿It is correct? It doesn't work.. ¿do I need to restart the server to apply the new rule?

Thank you.
Sep 10, 2008 at 12:42 AM

No, you do not need to restart the server .

Here's what I will do to help figure this out.

  1. create a new directory.
  2. in that directory, create a file called ISapiRewrite4.ini. That file will contain the exact rule you specified above.
  3. in the IsapiRewrite4.ini file, also put in the line "RewriteLogLevel 5" and the line "RewriteLogFile c:\temp\iirf" . The logfilename does not matter, but the line must be in there in order to get log output from the testdriver.exe.
  4. in the same directory, create a file called SampleUrls.txt and place in that file the line "/news/article/article-name /Clients/ClientName/web/news.php?article=article-name"
  5. run the testdriver.exe program, specify -d <DIRECTORYNAME>
  6. view the results.

What I found is that the rule does not match the incoming URL. I get a message on the testdriver.exe output that says "NO REWRITE". The relevant log file statement says "EvaluateRules: Rule 1 : -1 (No match)". This clearly indicates the rule does not match.

Why not? Well, a close inspection shows that there is a trailing slash in the pattern for the rule, but no trailing slash on the incoming URL. The incoming URL just ends in "article-name". So I removed the trailing slash from the pattern on the rule. I re-ran the test driver. It matches. it rewrites as you would expect.

the resulting rule is:

  RewriteRule news/(.*)/(.*)$     /Clients/ClientName/web/news.php?$1=$2

the end.