Directories to Query Parameters
6 posts
• Page 1 of 1
Directories to Query Parameters
Hi -
I'm having trouble rewriting folder names to query parameters. I want the URL:
/staticFolder1/staticFolder2/QueryParam1/QueryParam2/user.php?firstname=tj&lastname=test
to convert to:
/staticFolder1/staticFolder2/user.php?firstname=tj&lastname=test&QP=staticFolder1&Qp2=staticFolder2
I'm using the following rewrite rule:
RewriteRule ^staticFolder1/staticFolder2/?([^/]*)/?([^/]*)/user\.php(.*)$ user.php?cEdiUser=$1&LOID=$2&$3 [NC]
The rule works fine in regExTest, but the server doesn't seem to recognize it. Here is the URL and rewrite log:
http://testdomain.com/staticFolder1/sta ... 5/user.php
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (2) init rewrite engine with requested uri /staticFolder1/staticFolder2/a3332_qDev/X12345/user.php
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (1) Htaccess process request d:\inetpub\v1-2\v1-3\edi\.htaccess
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (3) applying pattern '^staticFolder1/staticFolder2/?([^/]*)/?([^/]*)/user\.php(.*)$' to uri '/staticFolder1/staticFolder2/a3332_qDev/X12345/user.php'
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (3) applying pattern '^(.*\.)(?:php|ahk)(.*)$' to uri '/staticFolder1/staticFolder2/a3332_qDev/X12345/user.php'
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (2) forcing proxy-throughput with http://192.168.0.94:8600/lpcontext//sta ... 5/user.cfm
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (1) go-ahead with proxy request http://192.168.0.94:8600/lpcontext//sta ... 5/user.cfm [OK]
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (1) Rewrite URL to >> /staticFolder1/staticFolder2/a3332_qDev/X12345/user.phpx.rwhlp?p=0
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (2) rewrite '/staticFolder1/staticFolder2/a3332_qDev/X12345/user.php' -> '/staticFolder1/staticFolder2/a3332_qDev/X12345/user.phpx.rwhlp?p=0'
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (2) internal redirect with /staticFolder1/staticFolder2/a3332_qDev/X12345/user.phpx.rwhlp?p=0 [INTERNAL REDIRECT]
Anyhelp is greatly appreciated.
Thanks
I'm having trouble rewriting folder names to query parameters. I want the URL:
/staticFolder1/staticFolder2/QueryParam1/QueryParam2/user.php?firstname=tj&lastname=test
to convert to:
/staticFolder1/staticFolder2/user.php?firstname=tj&lastname=test&QP=staticFolder1&Qp2=staticFolder2
I'm using the following rewrite rule:
RewriteRule ^staticFolder1/staticFolder2/?([^/]*)/?([^/]*)/user\.php(.*)$ user.php?cEdiUser=$1&LOID=$2&$3 [NC]
The rule works fine in regExTest, but the server doesn't seem to recognize it. Here is the URL and rewrite log:
http://testdomain.com/staticFolder1/sta ... 5/user.php
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (2) init rewrite engine with requested uri /staticFolder1/staticFolder2/a3332_qDev/X12345/user.php
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (1) Htaccess process request d:\inetpub\v1-2\v1-3\edi\.htaccess
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (3) applying pattern '^staticFolder1/staticFolder2/?([^/]*)/?([^/]*)/user\.php(.*)$' to uri '/staticFolder1/staticFolder2/a3332_qDev/X12345/user.php'
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (3) applying pattern '^(.*\.)(?:php|ahk)(.*)$' to uri '/staticFolder1/staticFolder2/a3332_qDev/X12345/user.php'
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (2) forcing proxy-throughput with http://192.168.0.94:8600/lpcontext//sta ... 5/user.cfm
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (1) go-ahead with proxy request http://192.168.0.94:8600/lpcontext//sta ... 5/user.cfm [OK]
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (1) Rewrite URL to >> /staticFolder1/staticFolder2/a3332_qDev/X12345/user.phpx.rwhlp?p=0
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (2) rewrite '/staticFolder1/staticFolder2/a3332_qDev/X12345/user.php' -> '/staticFolder1/staticFolder2/a3332_qDev/X12345/user.phpx.rwhlp?p=0'
192.168.0.2 192.168.0.2 Mon, 08-Oct-2012 10:26:27 GMT [testdomain.com/sid#1][rid#25365896/initial] (2) internal redirect with /staticFolder1/staticFolder2/a3332_qDev/X12345/user.phpx.rwhlp?p=0 [INTERNAL REDIRECT]
Anyhelp is greatly appreciated.
Thanks
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Directories to Query Parameters
Hello,
Please, try using the following:
RewriteCond %{QUERY_STRING} ^(firstname=[^&]+&lastname=[^&]+)$ [NC]
RewriteRule ^/staticFolder1/staticFolder2/?([^/]*)/?([^/]*)/user\.php$ /staticFolder1/staticFolder2/user.php?%1&QP=staticFolder1&Qp2=staticFolder2 [NC,L]
One of the problems your pattern wasn't recognized is the '/' in the beginning of the pattern.
Regards
Andrew
Please, try using the following:
RewriteCond %{QUERY_STRING} ^(firstname=[^&]+&lastname=[^&]+)$ [NC]
RewriteRule ^/staticFolder1/staticFolder2/?([^/]*)/?([^/]*)/user\.php$ /staticFolder1/staticFolder2/user.php?%1&QP=staticFolder1&Qp2=staticFolder2 [NC,L]
One of the problems your pattern wasn't recognized is the '/' in the beginning of the pattern.
Regards
Andrew
Re: Directories to Query Parameters
Thank you. That worked without the query parameters, but had to add the following to get it to work with query parameters:
(.*)
RewriteCond %{QUERY_STRING} ^(firstname=[^&]+&lastname=[^&]+)$ [NC]
RewriteRule ^/staticfolder1/staticfolder2/?([^/]*)/?([^/]*)/user\.php(.*)$ /staticfolder1/staticfolder2/user.php?$3&qp1=$1&qp2=$2 [NC]
Whats the difference between $3 and %1 after the the file extension? Couldn't i drop the rewritecond statement and just use $3? What would I do If I wanted to make this work with both query parameters and without?
(.*)
RewriteCond %{QUERY_STRING} ^(firstname=[^&]+&lastname=[^&]+)$ [NC]
RewriteRule ^/staticfolder1/staticfolder2/?([^/]*)/?([^/]*)/user\.php(.*)$ /staticfolder1/staticfolder2/user.php?$3&qp1=$1&qp2=$2 [NC]
Whats the difference between $3 and %1 after the the file extension? Couldn't i drop the rewritecond statement and just use $3? What would I do If I wanted to make this work with both query parameters and without?
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Directories to Query Parameters
The difference between %1 and $1 is that:
- %1 captures the value between the first set of '(' and ')' in the condition
- $3 captures the value between the third set of '(' and ')' in the rule
Couldn't i drop the rewritecond statement and just use $3?
- No, querystring parameter must be captured using the RewriteCond only!
Regards
Andrew
- %1 captures the value between the first set of '(' and ')' in the condition
- $3 captures the value between the third set of '(' and ')' in the rule
Couldn't i drop the rewritecond statement and just use $3?
- No, querystring parameter must be captured using the RewriteCond only!
Regards
Andrew
- tidaltides
- Posts: 24
- Joined: 27 Nov 2012, 21:57
Re: Directories to Query Parameters
So it means that:
% for condition
$ for rule
% for condition
$ for rule
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Directories to Query Parameters
That is correct.
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests