Successfulyl REWriting, but....

Topics: User Forum
Jul 17, 2009 at 5:23 PM

I am successfully rewriting, however I am finding that on certain pages, I need an additional querystring to be appended, however, all I get is a page not found.

so...  my URL looks like this:  http://www.xyz.com/page/23/album/23

which rewrites to http://www.xyz.com?page=23&album=23

however, I need to addon:

http://www.xyz.com/page/23/album/23?s=0&o=12

and have them not be rewritten.  How can I add this so it is processed correctly?

 

Here are my statements in .ini:

#---------- Photo Albums ---------#
RewriteRule ^/page/([^\?\/]+)/album/([^\?\/]+)$ /default.asp?page=$1&album=$2  [L]

Coordinator
Jul 17, 2009 at 7:23 PM

Try the [QSA] modifier on your rule.  It appends whatever querystring is on the original URL to the rewritten URL.

You need v2.0 or v1.2.16 (latest) to get this.

 

Coordinator
Jul 18, 2009 at 3:40 AM

you moved to another thread?

I'm not sure why.  On the other thread you said you are getting "page not found".  There are a number of possible reasons this can happen.

1 - IIRF did not load.  did you check the IIRF log file? Has IIRF loaded successfully?  Have you got any warnnigs or errors noted in the log file?

2 - No rules match the incoming request.  you will see this in the log file, too.    Your regex is not very complicated, so I would guess this is not the problem.  But it won't hurt to look in the log gile.

 

Jul 18, 2009 at 1:47 PM

sorry about posting in the other thead.

Here is the URL I am attempting (though it may not be correct...)

http://www.o7th.com/page/138?date=04/01/2009

While:
http://www.o7th.com/page/138

works as it should be, the appended querystring does not.  here is my new line in .ini

#------- Main Processing ---------#
RewriteRule ^/page/([^\?\/]+)$ /default.asp?page=$1  [QSA]

#---------- Blogs ----------------#
RewriteRule ^/page/([^\?\/]+)/blog/([^\?\/]+) /default.asp?page=$1&blog=$2  [QSA]

#---------- Photo Albums ---------#
RewriteRule ^/page/([^\?\/]+)/album/([^\?\/]+) /default.asp?page=$1&album=$2  [QSA]

Jul 18, 2009 at 1:49 PM

IIRF is loading correctly.  And the log for this is:

Sat Jul 18 09:47:55 -  2160 - HttpFilterProc: SF_NOTIFY_URL_MAP
Sat Jul 18 09:47:55 -  2160 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Sat Jul 18 09:47:55 -  2160 - DoRewrites
Sat Jul 18 09:47:55 -  2160 - GetHeader_AutoFree: 'url' = '/page/138?date=04%2F01%2F2009'
Sat Jul 18 09:47:55 -  2160 - GetHeader_AutoFree: 'method' = 'GET'
Sat Jul 18 09:47:55 -  2160 - DoRewrites: New Url: '/page/138?date=04%2F01%2F2009'
Sat Jul 18 09:47:55 -  2160 - EvaluateRules: depth=0
Sat Jul 18 09:47:55 -  2160 - EvaluateRules: Rule 1 : -1 (No match)
Sat Jul 18 09:47:55 -  2160 - EvaluateRules: Rule 2 : -1 (No match)
Sat Jul 18 09:47:55 -  2160 - EvaluateRules: Rule 3 : -1 (No match)
Sat Jul 18 09:47:55 -  2160 - EvaluateRules: Rule 4 : -1 (No match)
Sat Jul 18 09:47:55 -  2160 - EvaluateRules: returning 0
Sat Jul 18 09:47:55 -  2160 - DoRewrites: No Rewrite

Coordinator
Jul 18, 2009 at 2:30 PM

Your rule labeled "Main processing" includes a $ at the end of the pattern. $ means "end of line".  so that rule will match only if the URL starts with "/page", followed by a segment that includes no question marks or slashes.  (Then end of line).  When you add a question mark and a bunch of other text, in other words when you add a query string, the rule no longer matches the incoming URL.  Do you get that?

Removing the $ from the "Main processing" rule should allow your rule to match.

You could have tested all this using the TestDriver.exe program.  I suggest you look into that thing.  Many people work on their rules until 3 or 4 "correct" URLs work.  But a public website will get lots of "incorrect" URLs too - requests submitted by bots or other programs that don't match what you normally expect.   I know it's a console program, so maybe not the nicest to use, but it still is very useful for testing.   

Jul 18, 2009 at 2:56 PM

I found that if I do not include that $ in main processing, my other directives do not work.

here is all the processing:


#------- Main Processing ---------#
RewriteRule ^/page/([^\?\/]+)$ /default.asp?page=$1  [L]

#---------- Blogs ----------------#
RewriteRule ^/page/([^\?\/]+)/blog/([^\?\/]+)$ /default.asp?page=$1&blog=$2  [L]
RewriteRule ^/page/([^\?\/]+)/blog/date/([^\?\/]+) /default.asp?page=$1&date=$2  [L]

#---------- Photo Albums ---------#
RewriteRule ^/page/([^\?\/]+)/album/([^\?\/]+) /default.asp?page=$1&album=$2  [QSA]

and it works.

Thanks for your time

Coordinator
Jul 18, 2009 at 3:05 PM

oh, yeah, I forgot about that.  The "main processing" thing should be the last rule in the ini file.  As it is constructed, it will match all the good inputs.  You will be able to see that if you look in the log file.  It will show you that the first rule is matching all the inputs.  You don't want that.  So you need to re-order the rules, so that the more specialized forms occur first, before the thing you have labeled "Main processing" . 

And you still need to take out the $ and add the QSA.