How to get ampersand in unscrambles URL

Discuss practical ways rearrange URLs using mod_rewrite.

How to get ampersand in unscrambles URL

Postby Ritchie » Mon Dec 29, 2003 5:03 pm

I have the following in .htaccess......

Code: Select all
RewriteEngine On
Options +FollowSymLinks
RewriteBase /dev/
RewriteRule ^test/([^/]+)/([^/]+)/?(.*)$ test/$3?%{QUERY_STRING}$1=$2 [R]
RewriteRule ^test/$ test.php [L,R]


(I have used the R flag to see what is being done)
All works well, except I don't get the ampersand between each pair.

input..... mysite.com/dev/test/var1/val1/var3/val3/
output... mysite.com/dev/test.php?var1=val1var3=val3

How do I do that ?
Ritchie
 

Re: How to get ampersand in unscrambles URL

Postby iiinetworks » Mon Dec 29, 2003 7:46 pm

Does it work if you replace
Code: Select all
RewriteRule ^test/([^/]+)/([^/]+)/?(.*)$ test/$3?%{QUERY_STRING}$1=$2 [R]
with
Code: Select all
RewriteRule ^test/([^/]+)/([^/]+)/(.+)$ test/$3?%{QUERY_STRING}$1=$2& [R]
RewriteRule ^test/([^/]+)/([^/]+)$ test.php?%{QUERY_STRING}$1=$2 [L,R]
Or am I missing how it works?

Hth,
Matt
iiinetworks
 
Posts: 8
Joined: Sat Oct 11, 2003 11:53 am

Re: How to get ampersand in unscrambles URL

Postby Guest » Tue Dec 30, 2003 2:00 am

iiinetworks wrote:Does it work if you replace with
Code: Select all
RewriteRule ^test/([^/]+)/([^/]+)/(.+)$ test/$3?%{QUERY_STRING}$1=$2& [R]
RewriteRule ^test/([^/]+)/([^/]+)$ test.php?%{QUERY_STRING}$1=$2 [L,R]
Or am I missing how it works?


Hi Matt,

You think like me !!
I tried that, but the ampersand gets thrown away.
I even tried putting it immediately after the question mark - I then get a nice string of ampersands before the rest !
I'm going to see if I can find out just exactly what %{QUERY_STRING} does do !
Guest
 

Re: How to get ampersand in unscrambles URL

Postby Guest » Tue Dec 30, 2003 2:48 am

Ritchie wrote:I have the following in .htaccess......

Code: Select all
RewriteEngine On
Options +FollowSymLinks
RewriteBase /dev/
RewriteRule ^test/([^/]+)/([^/]+)/?(.*)$ test/$3%{QUERY_STRING}$1=$2 [R]
RewriteRule ^test/$ test.php [L,R]



I solved it !!!
The
Code: Select all
%{QUERY_STRING}
was the problem.
I removed that and added the flag
Code: Select all
[QSA]
Query String Append, and now it works - unlimted number of var/value pairs all nicely translated !!
Guest
 

Postby ecartz » Sat Sep 04, 2004 6:51 pm

To clarify, the following rules work as written:
Code: Select all
        Options +FollowSymLinks
        RewriteEngine On
        RewriteRule ^/directory/([^/.]+.php)/([^/]+)/([^/]+)(.*)$ /directory/$1$4?
$2=$3 [R=permanent,QSA]

        RewriteRule ^/directory/([^/.]+).php$ - [L,R]
for .php files located in a certain directory. The effect is to redirect from the path URL to a normal dynamic URL.
ecartz
 
Posts: 1
Joined: Fri Jan 23, 2004 3:43 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 114 guests

cron