views:

13

answers:

2

I have this url: http://localhost/zina/Artist%20One%20Demo?l=8&m=10&c And it needs to become: http://localhost/?p=Artist%20One%20Demol=8&m=10&c&option=com_zina&Itemid=82

I am using this to rewrite the url:

RewriteRule ^zina/(.*)?(.*)$ /?p=$1&$2&option=com_zina&Itemid=82 [L,R]

However, I wind up with urls that look like this: http://localhost/?p=Artist%20One%20Demo/Title%20One&&option=com_zina&Itemid=82

In otherwords, $2 is not being matched with anything. Can anyone tell me why?

A: 

This is off the cuff and not tested, but it looks like you are not escaping your ? in the rewrite regex so that it will treat it literally.

Try this maybe

RewriteRule ^zina/(.*)\?(.*)$ /?p=$1&$2&option=com_zina&Itemid=82 [L,R] 
Goblyn27
RewriteRule doesn't work at all if I escape the '?'
Malfist
+1  A: 

? is a special character (selects 0 or 1 of the previous pattern), .* is greedy (will match as far as it can go, so until the end, so $2 will always be empty as $1 eats everything until the end of the line.

The query string is not in the string the RewriteRule matches against, and checking for patterns in the query string would normally be done with RewriteCond %{QUERY_STRING} pattern before a RewriteRule.

However, we don't need to dabble with regexes to get the query string in the url:

RewriteRule ^zina/(.*)$ /?p=$1&option=com_zina&Itemid=82 [L,R,QSA]
Wrikken