MOD_REWRITE expressions
|
Taomyn
![]()
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, |
|
| Login or register to post comments |


Posts: 32356
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 sectionPosts: 135
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)
Posts: 389
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}Posts: 135
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)
Posts: 135
Right, ignore my question - I'm no closer, but I have found out a few things.
So far rules that almost works is:
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:
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)
Posts: 389
Awesome, what do you mean by "almost" work? I dont think you need the (.*) at the end of RewriteRule /v/([^?]+)(.*).
Posts: 135
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)
Posts: 32356
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.
Posts: 135
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)
Posts: 135
UPDATE
Currently my rules are:
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:
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)
Posts: 389
What if you make it two rules, like this:
Maybe this works.
Posts: 135
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?
Posts: 389
Allright, here's what they could look like:
Posts: 389
Btw, why is the RewriteCond Host needed?
Posts: 135
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)
Posts: 135
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)
Posts: 135
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:
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)
Posts: 32356
hard to believe...
Posts: 135
It's because Rewritebase isn't supported.
Here's the docs to ISAPI_Rewrite http://www.isapirewrite.com/docs/
Posts: 389
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:
Posts: 135
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)
Posts: 389
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.
Posts: 135
I finally had a chance to look at this again and have amended my rules as follows:
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)
Posts: 9
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
Posts: 389
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.
Posts: 6
can i get a link on were to download this isapi download??
Posts: 32356
wait 2-3 days and you can get it with the nightly snapshots.