MOD_REWRITE expressions

Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Tue, 2005-09-13 15:01

Now that G2 is live I'm trying to see how to get mod_rewrite support to work under Windows with ISAPI_REWRITE installed (this is the ISAPI module I used under IIS successfully with G1).

Indications during the beta phase of G2 showed that I probably won't be able to do this as the new mod_rewrite expressions for G2 contained code not supported but I'm hoping that maybe by now either a) the G2 expressions may have changed (doubtful) or b) the latest update has added the missing code.

Anyway, can some please tell me where or what the current expressions used are (I forget where I got them for the beta) so I can see if I can use them?

BTW - I thought the early beta of G2 used it's own built-in version of this which I'm sure worked under Windows, but then disappeared - or am I thinking of something else!?!?

Cheers,
Taomyn

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Tue, 2005-09-13 20:19

nothing has changed in this respect.

if someone can change his own rewrite rules such that they work for ISAPI, please submit and we may add support for ISAPI in future.

from my .htaccess (linux, apache 2):

# BEGIN Url Rewrite section
# (Automatically generated.  Do not edit this section)
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /gallery2/

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d [OR] 
    RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
    RewriteCond %{REQUEST_FILENAME} !main\.php
    RewriteRule .   -   [L]

    
    RewriteCond %{THE_REQUEST} \ /gallery2/admin/(\?.|\ .)
    RewriteCond %{REQUEST_FILENAME} !main\.php
    RewriteRule .   /gallery2/main.php?g2_view=core.SiteAdmin   [QSA,L]

    RewriteCond %{THE_REQUEST} \ /gallery2/v/(\?.|\ .)
    RewriteCond %{REQUEST_FILENAME} !main\.php
    RewriteRule .   /gallery2/main.php?g2_view=core.ShowItem   [QSA,L]

    RewriteCond %{THE_REQUEST} \ /gallery2/d/([0-9]+)-([0-9]+)/([^\/]+)(\?.|\ .)
    RewriteCond %{REQUEST_FILENAME} !main\.php
    RewriteRule .   /gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2   [QSA,L]

    RewriteCond %{THE_REQUEST} \ /gallery2/v/([^?]+)(\?.|\ .)
    RewriteCond %{REQUEST_FILENAME} !main\.php
    RewriteRule .   /gallery2/main.php?g2_view=core.ShowItem&g2_path=%1   [QSA,L]

</IfModule>

# END Url Rewrite section
Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Thu, 2005-09-22 16:55

Ok, things aren't going too well with the translation mainly because ISAPI_Rewrite doesn't support REQUEST_FILENAME, THE_REQUEST and QSA

I'm hoping I can get around these but I need to understand more what each rule is acheiving. I can get "show items" to work in general e.g. "http://gallery.co.uk/v/Cars/FV_100/2002_04_11_13_50_52.jpg.html" works, but then I get a link like "http://gallery.co.uk/v/Cars/FV_100/2002_04_11_13_50_52.jpg.html?g2_fromNavId=xa2a47f23" and Gallery no longer understands it.

Please, can anyone explain the rules and perhaps provide any example for each?

Cheers,
Taomyn

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.4
MySQL 4.1.12
Easysite 3.1.6, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Fri, 2005-09-23 08:10

Yay, a semi working ISAPI_rewrite :) I'll be glad to assist you in making this happen.

Now, on to your problem. As for show item I think I've seen an example where the user made two rules, one with and another withouth the query string. As you can se our mod_rewrite rule covers both cases in one rule. I don't know if you can do it with ISAPI_rewrite.

[QSA] means that the query string is appended to the existing one. This is the same as
RewriteRule <some pattern> main.php?bleh=whatever&%{QUERY_STRING}. What does your current rules look like?

For your ISAPI_rewrite I suggest you start with a few simple rules, mabye these work (I dont know ...)

RewriteRule v/([^?]+) main.php?g2_view=core.ShowItem&g2_path=$1&%{QUERY_STRING}
RewriteRule d/([0-9]+)-([0-9]+)/([^\/]+) main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&%{QUERY_STRING}
Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 08:54

Ok, sorry to sound dumb, but what is "([^?]+)" trying to match as I can't get the expression tester with ISAPI_Rewrite to match with this? If I use "(.*)" it works but is this the same?

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.4
MySQL 4.1.12
Easysite 3.1.6, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 10:27

Right, ignore my question - I'm no closer, but I have found out a few things.

So far rules that almost works is:

RewriteCond Host: gallery\.co\.uk
RewriteRule /v/(\?.|\ .) /main.php\?g2_view=core.ShowItem&%QUERY_STRING [I,L]

RewriteCond Host: gallery\.co\.uk
RewriteRule /v/([^?]+)(.*) /main.php\?g2_view=core.ShowItem&g2_path=$1&%QUERY_STRING [I,L]

Gives you a clue as to how ISAPI_Rewrite's syntax is.

I have discovered a couple of helpful variables in IIS that could help:

%THE_REQUEST does not exist in IIS6, but I think if you concatenate the variables "%REQUEST_METHOD %HTTP_X_REWRITE_URL %SERVER_PROTOCOL" you get the same thing assuming %THE_REQUEST includes the "query string" which the Apache docs don't tell me.

From above %QUERY_STRING should equate to QSA

%PATH_TRANSLATED I think equates to "%REQUEST_FILENAME" but here are all the IIS6 variables for reference:

ALL_HTTP:	HTTP_CONNECTION:keep-alive HTTP_KEEP_ALIVE:300 HTTP_ACCEPT:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_CHARSET:ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_ACCEPT_LANGUAGE:en-gb,en-us;q=0.7,en;q=0.3 HTTP_COOKIE:mwc=0001114112863.731526.5; login=fred@domain.co.uk%2Cen; Theme=LookOut; Lang=uk; User=fred; HTTP_HOST:www.domain.co.uk HTTP_USER_AGENT:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b5) Gecko/20050922 Firefox/1.4 HTTP_X_REWRITE_URL:/php/variables.asp?hhh=f&jjj=5
ALL_RAW:	Connection: keep-alive Keep-Alive: 300 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Accept-Language: en-gb,en-us;q=0.7,en;q=0.3 Cookie: mwc=0001114112863.731526.5; Host: www.domain.co.uk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b5) Gecko/20050922 Firefox/1.4 X-Rewrite-URL: /php/variables.asp?hhh=f&jjj=5
APPL_MD_PATH:	/LM/W3SVC/814671914/Root/php
APPL_PHYSICAL_PATH:	D:\wwwroot\php\
AUTH_PASSWORD:	
AUTH_TYPE:	
AUTH_USER:	
CERT_COOKIE:	
CERT_FLAGS:	
CERT_ISSUER:	
CERT_KEYSIZE:	
CERT_SECRETKEYSIZE:	
CERT_SERIALNUMBER:	
CERT_SERVER_ISSUER:	
CERT_SERVER_SUBJECT:	
CERT_SUBJECT:	
CONTENT_LENGTH:	0
CONTENT_TYPE:	
GATEWAY_INTERFACE:	CGI/1.1
HTTPS:	off
HTTPS_KEYSIZE:	
HTTPS_SECRETKEYSIZE:	
HTTPS_SERVER_ISSUER:	
HTTPS_SERVER_SUBJECT:	
INSTANCE_ID:	814671914
INSTANCE_META_PATH:	/LM/W3SVC/814671914
LOCAL_ADDR:	192.168.0.10
LOGON_USER:	
PATH_INFO:	/php/variables.asp
PATH_TRANSLATED:	D:\wwwroot\php\variables.asp
QUERY_STRING:	hhh=f&jjj=5
REMOTE_ADDR:	192.168.0.14
REMOTE_HOST:	192.168.0.14
REMOTE_USER:	
REQUEST_METHOD:	GET
SCRIPT_NAME:	/php/variables.asp
SERVER_NAME:	www.domain.co.uk
SERVER_PORT:	80
SERVER_PORT_SECURE:	0
SERVER_PROTOCOL:	HTTP/1.1
SERVER_SOFTWARE:	Microsoft-IIS/6.0
URL:	/php/variables.asp
HTTP_CONNECTION:	keep-alive
HTTP_KEEP_ALIVE:	300
HTTP_ACCEPT:	text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
HTTP_ACCEPT_CHARSET:	ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_ACCEPT_LANGUAGE:	en-gb,en-us;q=0.7,en;q=0.3
HTTP_COOKIE:	mwc=0001114112863.731526.5;
HTTP_HOST:	www.domain.co.uk
HTTP_USER_AGENT:	Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b5) Gecko/20050922 Firefox/1.4
HTTP_X_REWRITE_URL:	/php/variables.asp?hhh=f&jjj=5

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.4
MySQL 4.1.12
Easysite 3.1.6, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Fri, 2005-09-23 17:07

Awesome, what do you mean by "almost" work? I dont think you need the (.*) at the end of RewriteRule /v/([^?]+)(.*).

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 17:44

I mean I can access an album, then view an image but if I hit a tree link in the top left, where it says "Gallery » Cars » FV 100 » 2002-04-11 13.51.06" I click on "FV 100" which is "http://gallery.co.uk/v/Cars/FV_100/?g2_highlightId=271" doesn't work "Page not found" :(

I removed the (.*) and it made no difference.

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.4
MySQL 4.1.12
Easysite 3.1.6, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Fri, 2005-09-23 17:52

can you debug isapi rewrites? in apache mod_rewrite, you can enable rewrite logging or something like that and then you see exactly what's going on.

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 17:59

No not that I'm aware of except for syntax checking, but I'm tailing the IIS logs to see what things are getting changed to.

So far it appears %QUERY_STRING isn't working :(

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.4
MySQL 4.1.12
Easysite 3.1.6, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 18:51

UPDATE

Currently my rules are:

RewriteCond Host: gallery\.star-one\.co\.uk
RewriteRule /v/.*/\?(.*) /main.php/?g2_view=core.ShowItem&$1&rule=1 [I,L]

RewriteCond Host: gallery\.star-one\.co\.uk
RewriteRule /v/([^?]+) /main.php/?g2_view=core.ShowItem&g2_path=$1&rule=2 [I,L]

Ignore the "&rule" bits as they're just so I can see them in the logs better.

Here are the IIS logs showing me going from the root into an album then displaying a picture. Unfortunately as I reported before if I hit the link to go back into an album it fails and the browser shows simply .
/v as the URL:

#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status 
2005-09-23 18:41:19 192.168.0.10 GET /main.php/ g2_view=core.ShowItem&g2_path=Cars/FV_100/&rule=2 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 200 0 0
2005-09-23 18:41:19 192.168.0.10 GET /main.php g2_view=core.DownloadItem&g2_itemId=1536&g2_serialNumber=2 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 200 0 0
2005-09-23 18:41:22 192.168.0.10 GET /main.php/ g2_view=core.ShowItem&g2_path=Cars/FV_100/2002_04_11_13_50_52.jpg.html&rule=2 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 200 0 0
2005-09-23 18:41:22 192.168.0.10 GET /main.php g2_view=core.DownloadItem&g2_itemId=1317&g2_serialNumber=2 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 200 0 0
2005-09-23 18:41:25 192.168.0.10 GET /main.php/ g2_view=core.ShowItem&g2_highlightId=174&rule=1 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 302 0 0
2005-09-23 18:41:25 192.168.0.10 GET /v/ - 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 404 0 2
2005-09-23 18:41:51 192.168.0.10 GET /main.php/ g2_view=core.ShowItem&g2_highlightId=274&rule=1 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 302 0 0
2005-09-23 18:41:51 192.168.0.10 GET /v/ - 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 404 0 2
2005-09-23 18:43:48 192.168.0.10 GET /main.php g2_view=core.ShowItem&g2_highlightId=174 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 302 0 0
2005-09-23 18:43:48 192.168.0.10 GET /v/ - 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 404 0 2
2005-09-23 18:44:02 192.168.0.10 GET /v/ - 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 404 0 2
2005-09-23 18:44:05 192.168.0.10 GET /main.php/ g2_view=core.ShowItem&g2_highlightId=274&rule=1 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 302 0 0
2005-09-23 18:44:05 192.168.0.10 GET /v/ - 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 404 0 2
2005-09-23 18:45:04 192.168.0.10 GET /v/ - 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 404 0 2
#Software: Microsoft Internet Information Services 6.0
#Version: 1.0
#Date: 2005-09-23 18:45:50
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status 
2005-09-23 18:45:50 192.168.0.10 GET /main.php g2_view=core.ShowItem&g2_highlightId=174 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 302 0 0
2005-09-23 18:45:50 192.168.0.10 GET /v/ - 80 - 192.168.0.14 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322) 404 0 2

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.4
MySQL 4.1.12
Easysite 3.1.6, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Fri, 2005-09-23 18:52

What if you make it two rules, like this:

RewriteCond Host: gallery\.co\.uk
RewriteRule /v/([^?]+) /main.php\?g2_view=core.ShowItem&g2_path=$1 [I,L]
RewriteCond Host: gallery\.co\.uk
RewriteRule /v/([^?]+)?(.+) /main.php\?g2_view=core.ShowItem&g2_path=$1&$2 [I,L]

Maybe this works.

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 19:07
pelle wrote:
What if you make it two rules, like this:

RewriteCond Host: gallery\.co\.uk
RewriteRule /v/([^?]+) /main.php\?g2_view=core.ShowItem&g2_path=$1 [I,L]
RewriteCond Host: gallery\.co\.uk
RewriteRule /v/([^?]+)?(.+) /main.php\?g2_view=core.ShowItem&g2_path=$1&$2 [I,L]

Maybe this works.

You're a genius - I can't get my head around all of the regexp stuff and the tester that comes with ISAPI_Rewrite tends to confuse me at times.

I seem to be able to flit about viewing photos and clicking the links between albums.

Do these rules effect anything else?

The next question I suppose is to get the others working too?

Login or register to post comments
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Fri, 2005-09-23 19:26

Allright, here's what they could look like:

Show Item:
----------
RewriteCond Host: gallery\.co\.uk
RewriteRule /v/ /main.php\?g2_view=core.ShowItem [I,L]
RewriteCond Host: gallery\.co\.uk
RewriteRule /v/?(.+) /main.php\?$2 [I,L]
RewriteCond Host: gallery\.co\.uk
RewriteRule /v/([^?]+) /main.php\?g2_view=core.ShowItem&g2_path=$1 [I,L]
RewriteCond Host: gallery\.co\.uk
RewriteRule /v/([^?]+)?(.+) /main.php\?g2_view=core.ShowItem&g2_path=$1&$2 [I,L]
 
Download Item:
--------------
RewriteCond Host: gallery\.co\.uk
RewriteRule /d/([0-9]+)-([0-9]+)/([^\/]+) /main.php\?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2 [I,L]
RewriteCond Host: gallery\.co\.uk
RewriteRule /d/([0-9]+)-([0-9]+)/([^\/]+)?(.+) /main.php\?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&$4 [I,L]
 
Admin:
------
RewriteCond Host: gallery\.co\.uk
RewriteRule /admin/ /main.php\?g2_view=core.SiteAdmin [I,L]
RewriteCond Host: gallery\.co\.uk
RewriteRule /admin/?(.+) /main.php\?g2_view=core.SiteAdmin&$2 [I,L]
 
View Comments:
-------------
RewriteCond Host: gallery\.co\.uk
RewriteRule /c/view/([0-9]+).html /main.php\?g2_view=core.ItemAdmin&g2_subView=comment.ShowComments&g2_itemId=$1 [I,L]
RewriteCond Host: gallery\.co\.uk
RewriteRule /c/view/([0-9]+).html?(.+) /main.php\?g2_view=core.ItemAdmin&g2_subView=comment.ShowComments&g2_itemId=$1&$2 [I,L]
 
Add Comments:
-------------
RewriteCond Host: gallery\.co\.uk
RewriteRule /c/add/([0-9]+).html /main.php\?g2_view=core.ItemAdmin&g2_subView=comment.AddComment&g2_itemId=$1 [I,L]
RewriteCond Host: gallery\.co\.uk
RewriteRule /c/add/([0-9]+).html?(.+) /main.php\?g2_view=core.ItemAdmin&g2_subView=comment..AddComment&g2_itemId=$1&$2 [I,L]
Login or register to post comments
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Fri, 2005-09-23 19:34

Btw, why is the RewriteCond Host needed?

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 19:47

An initial run shows them to be failing - I did spot a couple of $2 which I think should be $1

I haven't got time to look at it at the moment, but will be able to look more closer later on.

Watch this space......

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.4
MySQL 4.1.12
Easysite 3.1.6, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 19:55

Further to previous before I go....

http://gallery.co.uk/v/Cars/ is caught by rule:

RewriteCond Host: gallery\.co\.uk
RewriteRule /v/?(.+) /main.php\?$1&rule=2 [I,L]

Which then fails as URL becomes "/main.php&Cars/"

Oops

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.4
MySQL 4.1.12
Easysite 3.1.6, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 21:54

Got back and took another look. This time I noticed that the "?" in the expressions weren't eascaped so I changed them all to "\?" and it seems to be working again so far.

Here's the latest version of the rules:

RewriteCond Host: gallery\.co\.uk
RewriteRule /v/ /main.php\?g2_view=core.ShowItem&rule=1 [I,L]

RewriteCond Host: gallery\.co\.uk
RewriteRule /v/\?(.+) /main.php\?$1&rule=2 [I,L]

RewriteCond Host: gallery\.co\.uk
RewriteRule /v/([^\?]+) /main.php\?g2_view=core.ShowItem&g2_path=$1&rule=3 [I,L]

RewriteCond Host: gallery\.co\.uk
RewriteRule /v/([^\?]+)\?(.+) /main.php\?g2_view=core.ShowItem&g2_path=$1&$2&rule=4 [I,L]
 
RewriteCond Host: gallery\.co\.uk
RewriteRule /d/([0-9]+)-([0-9]+)/([^\/]+) /main.php\?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&rule=5 [I,L]

RewriteCond Host: gallery\.co\.uk
RewriteRule /d/([0-9]+)-([0-9]+)/([^\/]+)\?(.+) /main.php\?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&$4&rule=6 [I,L]
 
RewriteCond Host: gallery\.co\.uk
RewriteRule /admin/ /main.php\?g2_view=core.SiteAdmin&rule=7 [I,L]

RewriteCond Host: gallery\.co\.uk
RewriteRule /admin/\?(.+) /main.php\?g2_view=core.SiteAdmin&$1&rule=8 [I,L]
 
RewriteCond Host: gallery\.co\.uk
RewriteRule /c/view/([0-9]+).html /main.php\?g2_view=core.ItemAdmin&g2_subView=comment.ShowComments&g2_itemId=$1&rule=9 [I,L]

RewriteCond Host: gallery\.co\.uk
RewriteRule /c/view/([0-9]+).html\?(.+) /main.php\?g2_view=core.ItemAdmin&g2_subView=comment.ShowComments&g2_itemId=$1&$2&rule=10 [I,L]
 
RewriteCond Host: gallery\.co\.uk
RewriteRule /c/add/([0-9]+).html /main.php\?g2_view=core.ItemAdmin&g2_subView=comment.AddComment&g2_itemId=$1&rule=11 [I,L]

RewriteCond Host: gallery\.co\.uk
RewriteRule /c/add/([0-9]+).html\?(.+) /main.php\?g2_view=core.ItemAdmin&g2_subView=comment..AddComment&g2_itemId=$1&$2&rule=12 [I,L]

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.4
MySQL 4.1.12
Easysite 3.1.6, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Fri, 2005-09-23 21:58
pelle wrote:
Btw, why is the RewriteCond Host needed?

hard to believe...

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-09-23 22:08
pelle wrote:
Btw, why is the RewriteCond Host needed?

It's because Rewritebase isn't supported.

Here's the docs to ISAPI_Rewrite http://www.isapirewrite.com/docs/

Login or register to post comments
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Sat, 2005-10-01 16:58

Here's an update of the rules:

Watermark:

RewriteCond Host: localhost
RewriteRule /gallery2/modules/rewrite/data/isapi_rewrite/Rewrite.txt /gallery2/modules/rewrite/data/isapi_rewrite/Works.txt [O]

      RewriteCond URL .*\?.*view=core.DownloadItem.*
      RewriteCond URL .*\?.*itemId=([0-9]+).*
  
      RewriteCond Referer: (?!.*://localhost/.*)
  
  
  RewriteCond Host: localhost
  RewriteRule /gallery2/.* /gallery2/main.php?g2_view=watermark.DownloadItem&g2_itemId=$1   [L]

Block hotlinked items:

RewriteCond Host: localhost
RewriteRule /gallery2/modules/rewrite/data/isapi_rewrite/Rewrite.txt /gallery2/modules/rewrite/data/isapi_rewrite/Works.txt [O]

      RewriteCond URL .*\?.*view=core.DownloadItem.*
  
      RewriteCond Referer: (?!.*://localhost/.*)
  
  
  RewriteCond Host: localhost
  RewriteRule /gallery2/.* /gallery2/main.php?   [F,L]

The "simple" rules:

# WITHOUTH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/slideshowapplet.html /gallery2/main.php?g2_view=slideshowapplet.SlideshowApplet   [N]

# WITH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/slideshowapplet.html\?(.*) /gallery2/main.php?g2_view=slideshowapplet.SlideshowApplet&$1   [N]

# WITHOUTH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/slideshow.html /gallery2/main.php?g2_view=slideshow.Slideshow   [N]
# WITH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/slideshow.html\?(.*) /gallery2/main.php?g2_view=slideshow.Slideshow&$1   [N]

# WITHOUTH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/admin/ /gallery2/main.php?g2_view=core.SiteAdmin   [N]
# WITH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/admin/\?(.*) /gallery2/main.php?g2_view=core.SiteAdmin&$1   [N]

# WITHOUTH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/ /gallery2/main.php?g2_view=core.ShowItem   [N]
# WITH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/\?(.*) /gallery2/main.php?g2_view=core.ShowItem&$1   [N]

# WITHOUTH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/([^?]+)/slideshowapplet.html /gallery2/main.php?g2_view=slideshowapplet.SlideshowApplet&g2_path=$1   [N]
# WITH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/([^?]+)/slideshowapplet.html\?(.*) /gallery2/main.php?g2_view=slideshowapplet.SlideshowApplet&g2_path=$1&$2   [N]

# WITHOUTH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/d/([0-9]+)-([0-9]+)/([^?]+) /gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3   [N]
# WITH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/d/([0-9]+)-([0-9]+)/([^?]+)\?(.*) /gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3&$4   [N]

# WITHOUTH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/([^?]+)/slideshow.html /gallery2/main.php?g2_view=slideshow.Slideshow&g2_path=$1   [N]
# WITH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/([^?]+)/slideshow.html\?(.*) /gallery2/main.php?g2_view=slideshow.Slideshow&g2_path=$1&$2   [N]

# WITHOUTH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/([^?]+) /gallery2/main.php?g2_view=core.ShowItem&g2_path=$1   [N]
# WITH Query String
RewriteCond Host: localhost
  RewriteRule /gallery2/v/([^?]+)\?(.*) /gallery2/main.php?g2_view=core.ShowItem&g2_path=$1&$2   [N]
Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Sat, 2005-10-01 18:23

Gulp, dunno where to start.

First thing I spot is that I think ISAPI_Rewrite is sensitive to spaces between blocks of RewriteCond and RewriteRule and you have places where there is a Rewritecond followed by a another then a space then another without a Rewriterule. To me the way the forum has displayed it makes it rather confusing.

Perhaps if you can supply it in a text file I can better see what is going on?

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.5
MySQL 4.1.13
Easysite 3.1.9, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Sun, 2005-10-02 16:27

I've tested them, so about the spaces it shouldn't be a problem.

And the update is only needed if you want the block/watermark hotlinked items. Other than that there's no big diffrent from your rules.

Login or register to post comments
Taomyn
Taomyn's picture

Joined: 2003-11-11
Posts: 135
Posted: Fri, 2005-10-14 02:52

I finally had a chance to look at this again and have amended my rules as follows:

# Gallery2 rules for mydomain.co.uk
# Testing rule
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /modules/rewrite/data/isapi_rewrite/Rewrite.txt /modules/rewrite/data/isapi_rewrite/Works.txt [I,L,O]

# WITHOUT Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /v/ /main.php?g2_view=core.ShowItem [I,L]
# WITH Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /v/\?(.*) /main.php?g2_view=core.ShowItem&$1 [I,L]

# WITHOUT Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /v/([^?]+)/slideshowapplet.html /main.php?g2_view=slideshowapplet.SlideshowApplet&g2_path=$1 [I,L]
# WITH Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /v/([^?]+)/slideshowapplet.html\?(.*) /main.php?g2_view=slideshowapplet.SlideshowApplet&g2_path=$1&$2 [I,L]

# WITHOUT Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /d/([0-9]+)-([0-9]+)/([^?]+) /main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3 [I,L]
# WITH Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /d/([0-9]+)-([0-9]+)/([^?]+)\?(.*) /main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3&$4 [I,L]

# WITHOUT Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /v/([^?]+)/slideshow.html /main.php?g2_view=slideshow.Slideshow&g2_path=$1 [I,L]
# WITH Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /v/([^?]+)/slideshow.html\?(.*) /main.php?g2_view=slideshow.Slideshow&g2_path=$1&$2 [I,L]

# WITHOUT Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /admin/ /main.php?g2_view=core.SiteAdmin [I,L]
# WITH Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /admin/\?(.*) /main.php?g2_view=core.SiteAdmin&$1 [I,L]

# WITHOUT Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /v/([^?]+) /main.php?g2_view=core.ShowItem&g2_path=$1 [I,L]
# WITH Query String
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteRule /v/([^?]+)\?(.*) /main.php?g2_view=core.ShowItem&g2_path=$1&$2 [I,L]

# Block hotlinked items
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteCond Referer: (?!.*://gallery\.mydomain\.co\.uk/.*)
RewriteCond URL .*\?.*view=core.DownloadItem.*
RewriteRule /.* /main.php? [F,I,L]

# Watermark
RewriteCond Host: gallery\.mydomain\.co\.uk
RewriteCond Referer: (?!.*://gallery\.mydomain\.co\.uk/.*)
RewriteCond URL .*\?.*view=core.DownloadItem.*
RewriteCond URL .*\?.*itemId=([0-9]+).*
RewriteRule /.* /main.php?g2_view=watermark.DownloadItem&g2_itemId=$1 [I,L]

They appear to work but I haven't gone too deep in testing them e.g. I don't have watermarks as yet.

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.5
MySQL 4.1.13
Easysite 3.1.9, FlashChat 4.0.6, FlashMyAdmin (fixed), FlashMyPDF, FlashBB
Gallery2 v1
phpBB 2.0.17 (+ PHP5 mod)

Login or register to post comments
jdphilli

Joined: 2002-08-30
Posts: 9
Posted: Thu, 2005-11-10 05:21

I have a question: if you got this to work with G1 on IIS, what are the contents of the httpd.ini file you used?
I am using G1 on IIS and do not wish to upgrade to G2.

Windows 2003 Service Pack 1
IIS 6 + PHP 5.0.5
Gallery v1

Login or register to post comments
pelle
pelle's picture

Joined: 2004-12-10
Posts: 389
Posted: Thu, 2005-11-10 18:01

If you search the forums I assure you that there's an answare to your question. I remember someone posting their IIS rewrite lines for G1 somewhere.

Login or register to post comments
dutch2005

Joined: 2005-09-26
Posts: 6
Posted: Sun, 2006-01-08 20:32

can i get a link on were to download this isapi download??

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Sun, 2006-01-08 21:55

wait 2-3 days and you can get it with the nightly snapshots.

Login or register to post comments