This forum has been moved here:
Helicon Tech Community Forum

ISAPI_Rewrite 3.0 (Forum Locked Forum Locked)
 Helicon Tech : ISAPI_Rewrite 3.0
Subject Topic: Match query string and parts of URL?
Author
Message |
adster101
Newbie


Joined: 23 November 2009
Location: United Kingdom
Posts: 6
Posted: 08 December 2011 at 4:29am

Hi All,

I'm having trouble doing the following with ISAPI rewrite 3 so any help here would be much appreciated as always.

I would like to do something as follows...

URL(s):
www.somedomain.co.uk/en/accommodation
www.somedomain.co.uk/en/accommodation/hotel/123456
www.somedomain.co.uk/en/accommodation/hotel/123456?param=4324
www.somedomain.co.uk/en/accommodation/hotel/123456?param=localinfo

I would like to rewrite these urls as follows...

/en/accommodation -> /index.php?alias=/en/accommodation

/en/accommodation/hotel/123456 -> /index.php?alias=/en/accommodation/hotel&id=123456

/en/accommodation/hotel/123456?param=5431 -> /index.php?alias=/en/accommodation/hotel&id=123456&id2=5431

I have something like this at the moment:

RewriteRule ^/en/?(?:([^/]+))?(?:/([^/]+))?(?:/([^/]+))?/?$ /index.php?alias=/en/$1/$2(?3&id=$3)

and another partial rule that picks up the query string part:

/en/(.*)\?(.*)$

but I am looking to combine these rules into one which is more generic (e.g. can be used for different url types but gives similar rewrites).

Can anyone help me, please?

Many thanks,

Adam


Back to Top Visit adster101's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 09 December 2011 at 8:00am

Practice shows that it's better to use several simple rules instead of complicated one.
In case you have these rules working we suggest that you have one analogue for first level URL, second level URL, etc.

Regards
Andrew
Back to Top
 
adster101
Newbie


Joined: 23 November 2009
Location: United Kingdom
Posts: 6
Posted: 13 December 2011 at 8:38am

Hi Andrew,

Thanks for getting back to me. I have got it working by using two rules as follows:

RewriteRule ^/en/?(?:([^/]+))?(?:/([^/]+))?(?:/([^/]+))\?(.*)/?$ /index.php?alias=/en/$1/$2(?3&id=$3)&$4 [L]
RewriteRule ^/en/?(?:([^/]+))?(?:/([^/]+))?(?:/([^/]+))?/?$ /index.php?alias=/en/$1/$2(?3&id=$3) [L]

So if the first doesn't match the second one does and vice versa. This seems to cover the various cases that I need which is cool.

However, I can't see how to merge these two rules into one. Surely there must be a way of optionally matching the query string...?

Many thanks,

Adam


Edited by adster101 - 13 December 2011 at 8:39am
Back to Top Visit adster101's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 14 December 2011 at 4:45am

Please, take a look at QSA-flag in the documentation.

Regards
Andrew
Back to Top
 

Sorry, you can NOT post a reply.
This forum has been locked by a forum administrator.

Printable version Printable version