Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
ISAPI_Rewrite 3.0 support forum
 Helicon Tech : ISAPI_Rewrite 3.0 support forum
Subject Topic: convert only first parameter to directory Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
DrdLord
Newbie
Newbie


Joined: 28 February 2008
Online Status: Offline
Posts: 8
Posted: 28 February 2008 at 1:38pm | IP Logged Quote DrdLord

I've got a script at /realtorlink/education/course.php it accepts 1 or 3 parameters  The first parameter I'd like to turn into a fake directory using RewriteRule but I want the 2nd and 3rd parameter if they exist to stay as parameters.  Preferably any amount of parameters should work, with the first being converted into a fake directory

current valid calls:
/realtorlink/education/course.php?courseCode=HI
/realtorlink/education/course.php?courseCode=HI&cid=32&sid=26

calls I want to direct to the previous calls:
/realtorlink/education/courses/HI.php
/realtorlink/education/courses/HI.php?cid=32&sid=26

rule I've been trying:
RewriteRule ^/realtorlink/education/courses/(.*).php(?:/?)?(cid=.*&sid=.*)? /realtorlink/education/course.php?courseCode=$1&$2

test data:
/realtorlink/education/courses/hi.php?cid=34&sid=24
/realtorlink/education/courses/hi.php
/realtorlink/education/courses/hi.phpgdfhsdf
/realtorlink/education/courses/hi.php?
/realtorlink/education/courses/hi.php?sfsdfsd


test results:
/realtorlink/education/course.php?courseCode=hi&
/realtorlink/education/course.php?courseCode=hi&
/realtorlink/education/course.php?courseCode=hi&
/realtorlink/education/course.php?courseCode=hi&
/realtorlink/education/course.php?courseCode=hi&

test desired results:
/realtorlink/education/course.php?courseCode=hi&cid=34&sid=24
/realtorlink/education/course.php?courseCode=hi
no match, (invalid file)
/realtorlink/education/course.php?courseCode=hi
/realtorlink/education/course.php?courseCode=hi



Edited by DrdLord - 28 February 2008 at 1:42pm
Back to Top View DrdLord's Profile Search for other posts by DrdLord
 
Anton
Moderator Group
Moderator Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Online
Posts: 4687
Posted: 29 February 2008 at 2:46am | IP Logged Quote Anton

Please try to use the following rule:

RewriteRule ^/realtorlink/education/courses/([^./]+)\.php$ /realtorlink/education/course.php?courseCode=$1 [NC,L,QSA]

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 
DrdLord
Newbie
Newbie


Joined: 28 February 2008
Online Status: Offline
Posts: 8
Posted: 29 February 2008 at 11:17am | IP Logged Quote DrdLord

Thanks that works
Back to Top View DrdLord's Profile Search for other posts by DrdLord
 
DrdLord
Newbie
Newbie


Joined: 28 February 2008
Online Status: Offline
Posts: 8
Posted: 03 March 2008 at 4:54pm | IP Logged Quote DrdLord

Ok new, related problem.  I need to recover the request string the user entered to get to this page, so if the user's address bar looks like this:
http://www.server.com/realtorlink/education/courses/HI.php?cid=1&sid=2

How do I get "/realtorlink/education/courses/HI.php?cid=1&sid=2"? I can only seem to get "/realtorlink/education/courses/HI.php" from HTTP_X_REWRITE_URL but that's missing the "?cid=1&sid=2".  If I use QUERY_STRING it has "courseCode=HI&cid=1&sid=2" not just the cid and sid parts.

Is there any way to recover the user's entire query before the rewrite rule touched it?
Back to Top View DrdLord's Profile Search for other posts by DrdLord
 
Yaroslav
Moderator Group
Moderator Group


Joined: 15 August 2002
Online Status: Offline
Posts: 6466
Posted: 04 March 2008 at 5:42am | IP Logged Quote Yaroslav

The original query string is appended to your rewritten URL, so you can access it as you have done it before rewrite.

__________________
Yaroslav Govorunov,
Helicon Tech
Back to Top View Yaroslav's Profile Search for other posts by Yaroslav Visit Yaroslav's Homepage
 
DrdLord
Newbie
Newbie


Joined: 28 February 2008
Online Status: Offline
Posts: 8
Posted: 04 March 2008 at 10:21am | IP Logged Quote DrdLord

I don't understand, where can I access it?

Normaly I'd use PATH_INFO and QUERY_STRING environment variables but they give "/realtorlink/education/course.php" and "courseCode=HI&cid=1&sid=2" respectivly. 

I want to redirect the user to the page they are currently on so I need to be able to retreive "/realtorlink/education/courses/HI.php?cid=1&sid=2".  All I can find is the environment variable HTTP_X_REWRITE_URL but it gives "/realtorlink/education/courses/HI.php".

I ether double the courseCode parameter or lose the cid and sid parameters.

Back to Top View DrdLord's Profile Search for other posts by DrdLord
 
Sergey
Moderator Group
Moderator Group


Joined: 11 March 2005
Online Status: Offline
Posts: 712
Posted: 05 March 2008 at 4:21am | IP Logged Quote Sergey

Try add this rule

#must be 1-st rule
RewriteHeader X-REWRITE-URL: (.*) $1 [QSA,NS]
Back to Top View Sergey's Profile Search for other posts by Sergey
 
DrdLord
Newbie
Newbie


Joined: 28 February 2008
Online Status: Offline
Posts: 8
Posted: 06 March 2008 at 11:25am | IP Logged Quote DrdLord

Thank you this works.

May I suggest for a future version to make a second environment variable to complement HTTP_X_REWRITE_URL? HTTP_X_REWRITE_QUERY to show the original query string.
Back to Top View DrdLord's Profile Search for other posts by DrdLord
 
David Mukaiwa
Newbie
Newbie


Joined: 19 September 2008
Location: South Africa
Online Status: Offline
Posts: 4
Posted: 19 September 2008 at 7:56am | IP Logged Quote David Mukaiwa

I have a similar issue but the parameter I want to convert to a 'directory' may be in any position. All other url query string parameters should remain intact. Besides the parameter transformation, I would also like to redirect to another domain All in one rule if possible. My scenarion looks something like this:

Given either of the following URL's

http://originaldomain.com/Dir1?prmX=valX&prmY=valY&prmZ=valZ
http://originaldomain.com/Dir1?prmY=valY&prmZ=valZ&prmX=valX

I would like to redirect to the following

http://newdomain.com/Dir1/valX/?prmY=valY&prmZ=valZ

I hope that makes sense. Any help would be appreciated.

Thanks,

David
Back to Top View David Mukaiwa's Profile Search for other posts by David Mukaiwa Visit David Mukaiwa's Homepage
 
Anton
Moderator Group
Moderator Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Online
Posts: 4687
Posted: 22 September 2008 at 2:39am | IP Logged Quote Anton

It's rather difficult to do it in a single rule, so please try to use the following config:

RewriteBase /
RewriteCond %{QUERY_STRING} ^prmX=([^&]+)&(prmY=[^&]+&prmZ=[^&]+)$ [NC]
RewriteRule ^Dir1$ http://newdomain.com/Dir1/%1/?%2? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(prmY=[^&]+&prmZ=[^&]+)&prmX=([^&]+)$ [NC]
RewriteRule ^Dir1$ http://newdomain.com/Dir1/%2/?%1? [NC,R=301,L]

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 
David Mukaiwa
Newbie
Newbie


Joined: 19 September 2008
Location: South Africa
Online Status: Offline
Posts: 4
Posted: 01 October 2008 at 3:54am | IP Logged Quote David Mukaiwa

Whoah!

Thanks Anton,

I'll give it a shot and let you know how I fare.
Back to Top View David Mukaiwa's Profile Search for other posts by David Mukaiwa Visit David Mukaiwa's Homepage
 
David Mukaiwa
Newbie
Newbie


Joined: 19 September 2008
Location: South Africa
Online Status: Offline
Posts: 4
Posted: 07 October 2008 at 8:43am | IP Logged Quote David Mukaiwa

Hi Anton,

I tried the config you gave me and it seems that %{QUERY_STRING} is a feature specific to version 3. The server on which i need to implement this runs 2.10.0.53 and changing that is out my jurisdiction. Whatever I do must work without installing new stuff.

Here is a pseudo set of rules that I wanna rewrite as regex.

Conventions used in the pseudo rule set:

$Variable name
Text to be captured
Text to be dropped
Captured or injected text

Although it may be possible to implement this using fewer but more complex rules, it’ll be easier to maintain if I implemented it as modular solution comprised of 4 separate rules as follows:

1.       Request URL starts with “http://oldDomain.com/specialFolder$restofURL
Rewrite URL as “http://newDomain.com/specialFolder$restofURL”.
Continue processing

2.       Request URL starts with “http://newDomain.com/specialFolder?sprmName=$prmValue&$restOfQuerystring”,
Rewrite URL as “http://newDomain.com/specialFolder/$prmValue?$restofQuerystring
Stop processing

Request URL is in the format “http://newDomain.com/specialFolder?$querystringFragment1&prmName=$prmValue&$restofURL
Rewrite URL as “http://newDomain.com/specialFolder/$prmValue?$querystringFragment1&$restofURL
Stop processing

I would appreciate your help with this. I hope this makes sense.

Thanks,

David



Edited by David Mukaiwa - 08 October 2008 at 3:21am
Back to Top View David Mukaiwa's Profile Search for other posts by David Mukaiwa Visit David Mukaiwa's Homepage
 
Anton
Moderator Group
Moderator Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Online
Posts: 4687
Posted: 08 October 2008 at 3:33am | IP Logged Quote Anton

Please try to apply the following ruleset:

RewriteCond Host: (?:www\.)?olddomain.com
RewriteRule (/specialFolder/.*) http://newDomain.com$1 [I,R]

RewriteCond Host: (?:www\.)?newdomain.com
RewriteRule (/specialFolder)\?sprmName=([^&]+)&(.*) $1/$2\?$3 [I,L]

RewriteCond Host: (?:www\.)?newdomain.com
RewriteRule (/specialFolder)\?([^&]+)&sprmName=([^&]+)&(.*) $1/$3\?$2&$4 [I,L]



__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You can vote in polls in this forum