| Author |
|
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 25 November 2009 at 2:35pm | IP Logged
|
|
|
Hi everyone first post here, and looking for some help if at all possible.
I write and support a url rewrite module (GNU/GPL) previous versions of which only work on *nix servers the module now works for Windows servers but only in a "non rewrite" mode, the reason for this is twofold.
1) I only just grasped PCRE to a moderately exceptable level which made my head explode.
2) I have no access to a Windows server.
I have users who use ISAPI rewrite and some have "cobbled together" a "sort of working" solution but if at all possible would like to offer them a solid solution.
I read through some of the forum and noticed the use of mapping which looks a very nice.
The current mod_rewrite is very simplistic and looks as below: -
RewriteEngine on RewriteBase /<dir structure>/ RewriteRule ^(.*)-z-([0-9_]+).html$ index.php [L,QSA]
The -z- is a static marker which would relate (map?) always to a specific page, in this case index.php.
So the structure, such as it is, goes ..
a) Anything before the marker (-z-).
b) In between the marker (-z-) and the .html any number of digits including any number of underscores.
c) Any querystring re added
d) The -z- has to rewrite to a specific php file
As the program is not a monolithic structure there would be loads of these e.g.
RewriteRule ^(.*)-y-([0-9_]+).html$ another_file.php [L,QSA]
Which is why mapping looks good.
What I would really like to do is offer users the ISAPI version of a finished .htaccess whith all RewriteRules.
Any and all help gratefully received.
|
| Back to Top |
|
| |
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 25 November 2009 at 2:39pm | IP Logged
|
|
|
I'll have to be careful here, I'm used to being able to edit my typos so usually don't pay much attention to the initial posting.
|
| Back to Top |
|
| |
Anton Admin Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 10520
|
| Posted: 26 November 2009 at 2:42am | IP Logged
|
|
|
So is you issue already solved? Actually there's a possibility to edit posts on this forum. There's an edit button.
__________________ Regards,
Anton
|
| Back to Top |
|
| |
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 26 November 2009 at 12:01pm | IP Logged
|
|
|
Anton wrote:
| So is you issue already solved? Actually there's a possibility to edit posts on this forum. There's an edit button. |
|
|
No the question remains as above.
Still can't see an edit button .. must be blind.
|
| Back to Top |
|
| |
Anton Admin Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 10520
|
| Posted: 27 November 2009 at 3:37am | IP Logged
|
|
|
So you want to go to a specific php page depending on the letter between the dashes, e.g. '-z-' or '-y-'.
And should the values before and after this part be accounted for? If yes, then how?
Please provide some specific examples of what you want to request and what should be the result.
__________________ Regards,
Anton
|
| Back to Top |
|
| |
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 27 November 2009 at 5:08pm | IP Logged
|
|
|
It is as I explained .. I don't need to pass the captured values at all e.g.
I don't need ..
RewriteRule ^(.*)-z-([0-9_]+).html$ index.php?somekey=$2
to pass the value of the sub-expression between the -z- and the .html as I retrieve this information via PHP and REQUEST_URI (and my Windows replication of it).
Before the -z- can be anything [a-z0-9-/] (this could be path style values like e.g /brand/model/product-name) this is seo stuff but irrelevant to the script and unused.
The php script explodes the uri via the -z- and extracts the value before the .html.
The .html is important as the uri types not using rewriterules do not have .html and therefore do not trigger the rule.
Hope that makes some sense.
|
| Back to Top |
|
| |
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 27 November 2009 at 5:28pm | IP Logged
|
|
|
A little more specific info in case it helps.
Uri types requiring rewrite:
brand-category-product-name-z-32.html
brand/category/product-name-z-32.html
Non rewrite uri types:
index.php/brand-category-product-name-z-32
index.php/brand/category/product-name-z-32
The non rewrite versions must not trigger the rewriterules
The rewrite versions must be directed to the correct file.php by matching the marker ( -z- etc ).
I only used index.php as an example there are multiple php files.
|
| Back to Top |
|
| |
Anton Admin Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 10520
|
| Posted: 30 November 2009 at 3:20am | IP Logged
|
|
|
Please consider havinf mapfile.txt like this:
z file.pfp
y otherfile.php
etc.
And use the config like this:
RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:mapfile.txt
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*-([a-z])-[0-9_]+\.html$ ${mapfile:$1} [NC,L]
__________________ Regards,
Anton
|
| Back to Top |
|
| |
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 02 December 2009 at 12:21pm | IP Logged
|
|
|
Anton wrote:
Please consider havinf mapfile.txt like this:
z file.pfp
y otherfile.php
etc.
And use the config like this:
RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:mapfile.txt
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*-([a-z])-[0-9_]+\.html$ ${mapfile:$1} [NC,L] |
|
|
Anton
Thanks very much for taking the time to reply and for the code, much appreciated.
Sadly it looks like I can't use RewriteMap as this has to be set in apache config and most users do not have access, shame as it is nice functionality.
So .. it looks like I am back to multiple instances of ..
RewriteEngine on RewriteBase /<directory path>/ RewriteRule ^([a-z0-9-/]+)-z-([0-9_]+).html$ index.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-y-([0-9_]+).html$ anotherfile.php [NC,L,QSA] # loads more here
I only recently noticed that ISAPI 3.0 actually uses PCRE now. Does this mean that my apache rewrites as above would in fact work on a Windows server that had ISAPI rewrite or are there differences?
Also would they just be added to a .htaccess or is there more that I would need to instruct people to do?
|
| Back to Top |
|
| |
Anton Admin Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 10520
|
| Posted: 03 December 2009 at 5:10am | IP Logged
|
|
|
"Does this mean that my apache rewrites as above would in fact work on a Windows server that had ISAPI rewrite or are there differences?" -
generally, it should work just the same as Apache in 99% of cases, but as there are differences in Windows and Unix ideology, some small
distinctions are possible.
If you show me your Apache rules, I'll tell whether they will work in ISAPI_Rewrite as is, otherwise I'll fix them for you.
__________________ Regards,
Anton
|
| Back to Top |
|
| |
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 06 December 2009 at 9:31am | IP Logged
|
|
|
Anton wrote:
"Does this mean that my apache rewrites as above would in fact work on a Windows server that had ISAPI rewrite or are there differences?" -
generally, it should work just the same as Apache in 99% of cases, but as there are differences in Windows and Unix ideology, some small
distinctions are possible.
If you show me your Apache rules, I'll tell whether they will work in ISAPI_Rewrite as is, otherwise I'll fix them for you. |
|
|
Anton thanks for your continued help and support.
The full addition to .htaccess is as below: -
# If you are getting errors you may need to comment this out like .. # Options +FollowSymLinks Options +FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On
# RewriteBase instructions # Change RewriteBase dependent on how your shop is accessed as below. # http://www.mysite.com = RewriteBase / # http://www.mysite.com/catalog/ = RewriteBase /catalog/ # http://www.mysite.com/catalog/shop/ = RewriteBase /catalog/shop/
# Change RewriteBase using the instructions above RewriteBase / RewriteRule ^([a-z0-9-/]+)-p-([0-9]+).html$ product_info.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-c-([0-9_]+).html$ index.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-m-([0-9]+).html$ index.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-pi-([0-9]+).html$ popup_image.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-pr-([0-9]+).html$ product_reviews.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-pri-([0-9]+).html$ product_reviews_info.php [NC,L,QSA] # Articles contribution RewriteRule ^([a-z0-9-/]+)-t-([0-9_]+).html$ articles.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-a-([0-9]+).html$ article_info.php [NC,L,QSA] # Information pages RewriteRule ^([a-z0-9-/]+)-i-([0-9]+).html$ information.php [NC,L,QSA] # Links contribution RewriteRule ^([a-z0-9-/]+)-links-([0-9_]+).html$ links.php [NC,L,QSA] # Newsdesk contribution RewriteRule ^([a-z0-9-/]+)-n-([0-9]+).html$ newsdesk_info.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-nc-([0-9]+).html$ newsdesk_index.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-nri-([0-9]+).html$ newsdesk_reviews_info.php [NC,L,QSA] RewriteRule ^([a-z0-9-/]+)-nra-([0-9]+).html$ newsdesk_reviews_article.php [NC,L,QSA] </IfModule>
|
| Back to Top |
|
| |
Anton Admin Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 10520
|
| Posted: 07 December 2009 at 3:25am | IP Logged
|
|
|
This config should work for you just fine:
RewriteEngine On
# RewriteBase instructions
# Change RewriteBase dependent on how your shop is accessed as below.
# http://www.mysite.com = RewriteBase /
# http://www.mysite.com/catalog/ = RewriteBase /catalog/
# http://www.mysite.com/catalog/shop/ = RewriteBase /catalog/shop/
# Change RewriteBase using the instructions above
RewriteBase /
RewriteRule ^([a-z0-9-/]+)-p-([0-9]+)\.html$ product_info.php [NC,L,QSA]
RewriteRule ^([a-z0-9-/]+)-c-([0-9_]+)\.html$ index.php [NC,L,QSA]
RewriteRule ^([a-z0-9-/]+)-m-([0-9]+)\.html$ index.php [NC,L,QSA]
RewriteRule ^([a-z0-9-/]+)-pi-([0-9]+)\.html$ popup_image.php [NC,L,QSA]
RewriteRule ^([a-z0-9-/]+)-pr-([0-9]+)\.html$ product_reviews.php [NC,L,QSA]
RewriteRule ^([a-z0-9-/]+)-pri-([0-9]+)\.html$ product_reviews_info.php [NC,L,QSA]
# Articles contribution
RewriteRule ^([a-z0-9-/]+)-t-([0-9_]+)\.html$ articles.php [NC,L,QSA]
RewriteRule ^([a-z0-9-/]+)-a-([0-9]+)\.html$ article_info.php [NC,L,QSA]
# Information pages
RewriteRule ^([a-z0-9-/]+)-i-([0-9]+)\.html$ information.php [NC,L,QSA]
# Links contribution
RewriteRule ^([a-z0-9-/]+)-links-([0-9_]+)\.html$ links.php [NC,L,QSA]
# Newsdesk contribution
RewriteRule ^([a-z0-9-/]+)-n-([0-9]+)\.html$ newsdesk_info.php [NC,L,QSA]
RewriteRule ^([a-z0-9-/]+)-nc-([0-9]+)\.html$ newsdesk_index.php [NC,L,QSA]
RewriteRule ^([a-z0-9-/]+)-nri-([0-9]+)\.html$ newsdesk_reviews_info.php [NC,L,QSA]
RewriteRule ^([a-z0-9-/]+)-nra-([0-9]+)\.html$ newsdesk_reviews_article.php [NC,L,QSA]
__________________ Regards,
Anton
|
| Back to Top |
|
| |
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 07 December 2009 at 11:24am | IP Logged
|
|
|
Ok Anton that seems unchanged, is that correct?
So my users can create a .htaccess in root (just like apache) add that code in and it'll work?
Can I also confirm that this will only work for ISAPI Rewrite vs 3.0?
Do I need anything to support 2.0?
Once I get this all tied up I will commence recommending Windows users to install ISAPI Rewrite 
|
| Back to Top |
|
| |
Anton Admin Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 10520
|
| Posted: 08 December 2009 at 4:07am | IP Logged
|
|
|
Yes, it's ALMOST the same as you provided (there are some minor changes).
"So my users can create a .htaccess in root (just like apache) add that code in and it'll work?" - yes, exactly.
"Can I also confirm that this will only work for ISAPI Rewrite vs 3.0?" - yes, this config will work in v3.
"Do I need anything to support 2.0?" - do you need the same config to work with v2 as well? If yes, I'll give you the converted config.
__________________ Regards,
Anton
|
| Back to Top |
|
| |
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 11 December 2009 at 2:47am | IP Logged
|
|
|
It depends what my users will have on their server, if in your opinion there are loads of servers out there still on version 2.0 then it would make sense for me to offer a solution for it.
|
| Back to Top |
|
| |
Anton Admin Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 10520
|
| Posted: 11 December 2009 at 4:56am | IP Logged
|
|
|
Ok, here's the corresponding config for v2:
[ISAPI_Rewrite]
RewriteRule /([a-z0-9-/]+)-p-([0-9]+)\.html /product_info.php [I,L]
RewriteRule /([a-z0-9-/]+)-c-([0-9_]+)\.html /index.php [I,L]
RewriteRule /([a-z0-9-/]+)-m-([0-9]+)\.html /index.php [I,L]
RewriteRule /([a-z0-9-/]+)-pi-([0-9]+)\.html /popup_image.php [I,L]
RewriteRule /([a-z0-9-/]+)-pr-([0-9]+)\.html /product_reviews.php [I,L]
RewriteRule /([a-z0-9-/]+)-pri-([0-9]+)\.html /product_reviews_info.php [I,L]
# Articles contribution
RewriteRule /([a-z0-9-/]+)-t-([0-9_]+)\.html /articles.php [I,L]
RewriteRule /([a-z0-9-/]+)-a-([0-9]+)\.html /article_info.php [I,L]
# Information pages
RewriteRule /([a-z0-9-/]+)-i-([0-9]+)\.html /information.php [I,L]
# Links contribution
RewriteRule /([a-z0-9-/]+)-links-([0-9_]+)\.html /links.php [I,L]
# Newsdesk contribution
RewriteRule /([a-z0-9-/]+)-n-([0-9]+)\.html /newsdesk_info.php [I,L]
RewriteRule /([a-z0-9-/]+)-nc-([0-9]+)\.html /newsdesk_index.php [I,L]
RewriteRule /([a-z0-9-/]+)-nri-([0-9]+)\.html /newsdesk_reviews_info.php [I,L]
RewriteRule /([a-z0-9-/]+)-nra-([0-9]+)\.html /newsdesk_reviews_article.php [I,L]
__________________ Regards,
Anton
|
| Back to Top |
|
| |
thunderace Newbie

Joined: 25 November 2009
Online Status: Offline Posts: 10
|
| Posted: 11 December 2009 at 1:20pm | IP Logged
|
|
|
Thanks very much Anton I believe I have all that's needed and will let you know how it goes .. I'll promote helicontech to all the Windows users.
Can I confirm lastly that in both cases the rules go in a .htaccess file just like an apache server.
|
| Back to Top |
|
| |