| Author |
|
siteone Groupie

Joined: 07 March 2007 Location: United Kingdom
Online Status: Offline Posts: 51
|
| Posted: 28 July 2011 at 9:25am | IP Logged
|
|
|
Hi All,
I'm endeavouring to get rewriting to work using mod_dbd.
Here is the rewrite:
RewriteEngine On RewriteBase
DBDriver mssql DBDParams "Data Source=localhost;Initial Catalog=XXXX;User ID=XXXX;Password=XXX" DBDPrepareSQL "SELECT CID FROM Categories WHERE LOWER(REPLACE(Category,' ','-'))=@KEY" ton_map_select1
#Categories RewriteMap map_dbd_cat dbd:ton_map_select1 RewriteCond ${map_dbd_cat:$1|NOT_FOUND} (.*) RewriteCond %1 !NOT_FOUND RewriteRule ^/([^?/]+)$ prod.asp?CID=2 [NC,L]
The problem is I get the following error:
[28/07/2011 15:03:14] [.htaccess] (4) [/brother-toner-cartridges] Internal error - exception in rewrite_module: Unable to cast object of type 'System.Int32' to type 'System.String'.
I just cant see where I'm going wrong. If I replace the query with 'SELECT Category' and replace prod.asp?CID=2, I can force the rewrite to work.
CID is an integer and Category is a string in the db table. My suspicion is that @key is picking up an integer. I used the exact same code on another site which worked fine.
Any help would be greatly appreciated.
Regards, SiteOne
|
| Back to Top |
|
| |
Vyacheslav Admin Group

Joined: 02 July 2008 Location: Ukraine
Online Status: Offline Posts: 1542
|
| Posted: 28 July 2011 at 10:18am | IP Logged
|
|
|
Hello.
Please try to surround @key with quotes or use CAST function. Most likely MSSQL takes @KEY as integer.
__________________ Slavik Shynkarenko,
Helicon Tech.
|
| Back to Top |
|
| |
siteone Groupie

Joined: 07 March 2007 Location: United Kingdom
Online Status: Offline Posts: 51
|
| Posted: 28 July 2011 at 10:40am | IP Logged
|
|
|
Hi Vyacheslav,
Thank you for the fast response.
I've tried quotes and cast. Instead of an internal server error I get a 404 now. heres a log snippet:
init rewrite engine with /brother-toner-cartridges applying pattern ^(.+)$ to uri /brother-toner-cartridges RewriteCond: input='NOT_FOUND' pattern='(.*)' => matched RewriteCond: input='NOT_FOUND' pattern='NOT_FOUND' => not-matched
Here's the SQL query:
DBDPrepareSQL "SELECT CID FROM Categories WHERE LOWER(REPLACE(Category,' ','-'))=CAST(@Key AS varchar(255)) " \ ton_map_select1
If I leave the rewrite rule to RewriteRule ^/(.+)$ prod.asp?CID=%1 [L] I get the cast error but removing the / gives me a 404.
|
| Back to Top |
|
| |
siteone Groupie

Joined: 07 March 2007 Location: United Kingdom
Online Status: Offline Posts: 51
|
| Posted: 28 July 2011 at 11:15am | IP Logged
|
|
|
This works returning a string for CID
DBDPrepareSQL "SELECT Category FROM Categories WHERE LOWER(REPLACE(Category,' ','-'))=CAST(@Key AS varchar(255)) " ton_map_select1
#Categories RewriteMap map_dbd_cat dbd:ton_map_select1 RewriteCond ${map_dbd_cat:$1|NOT_FOUND} (.*) RewriteCond %1 !NOT_FOUND RewriteRule ^/(.+)$ prod.asp?CID=%1 [L]
This returns an internal server error with the cast error in the error log
DBDPrepareSQL "SELECT CID FROM Categories WHERE LOWER(REPLACE(Category,' ','-'))=CAST(@Key AS varchar(255)) " ton_map_select1
#Categories RewriteMap map_dbd_cat dbd:ton_map_select1 RewriteCond ${map_dbd_cat:$1|NOT_FOUND} (.*) RewriteCond %1 !NOT_FOUND RewriteRule ^/(.+)$ prod.asp?CID=%1 [L]
Hope this helps...
|
| Back to Top |
|
| |
siteone Groupie

Joined: 07 March 2007 Location: United Kingdom
Online Status: Offline Posts: 51
|
| Posted: 29 July 2011 at 4:16am | IP Logged
|
|
|
Hi All,
I have managed to get this to work:
DBDPrepareSQL "SELECT CAST(CID AS varchar(255)) AS vCID FROM Categories WHERE LOWER(REPLACE(Category,' ','-'))= @Key" ton_map_select1
CASTing CID rather than @key did the trick. But I still don't understand why I didn't have to do this on a similar site on the same server. The only difference between the two is that this site is written in classic ASP and the one where I had no problems is written in ASP.Net C#.
Thank you Vyacheslav for the CASTing tip!
Regs, SiteOne
|
| Back to Top |
|
| |
Vyacheslav Admin Group

Joined: 02 July 2008 Location: Ukraine
Online Status: Offline Posts: 1542
|
| Posted: 29 July 2011 at 6:58am | IP Logged
|
|
|
Hi.
I’m glad you got it working. I just wanted to add regarding the / character.
The reason is that you use RewriteBase directive with no arguments. Please see http://www.helicontech.com/ape/doc/mod_rewrite.htm#RewriteBase for more information.
Thank you.
__________________ Slavik Shynkarenko,
Helicon Tech.
|
| Back to Top |
|
| |