1

I have the following url:

http://www.domain.gr/add-event?state=3cb7a28b14112d3f3ecada3d6915ac5f&code=AQAZeWtJgz1ZYWvsorRPiMRetkNhnU3NrQ9KYzIRkogUpg6IPHCkFCAWMBUYGYtulfWnr5JHWs2GbrBUAp89pVLStyKs_rer2r14yLI6qdByoqEv1TtHGK4TPzdLFRTgXZEzPEUyk9ixYQfdmZid0dRdTfVXDPqniCKnu8RHQb1ErRDezsdI2CcYsTxofe_wwtZYVD3d4r9VtlANrGn_klP1#_=_ 

My RewriteRule works fine with urls like http://www.doamin.gr/news/date/title-of-article setting 'news' as $_GET['page'] and $_GET['request'] to '/date/title-of-article' My htaccess has the following code in order to provide clean urls:

RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)(.*)$ /index.php?page=$1&request=$2 

With the above url $_GET is set as follows:

$_GET['page'] = 'add-event'; $_GET['request'] = ''; // blank

How should I modify the reqriteRule in order to get the remaining part of the url in this case?(without messing up my clean urls).

0x_Anakin
  • 3,229
  • 5
  • 47
  • 86
  • In the long URL at the top I see 2 keys `state` and `code`. Then, it seems their values are trying to be captured in the rule. ¿Is that right? If so, the regex should group everything after `state=` and everything after `code=` and it is not doing it. If not, please explain more in detail what the problem is. – Felipe Alameda A Jan 21 '13 at 22:39
  • well up untill now i didnt have get variables on my clean urls so www.domain.gr/pagename/rest-url would assign $_GET['page'] = pagename and $_GET['request'] = /rest-url. But in this case of this long url $_GET['request'] returns empty what I would like it to return would be everything after the '?' – 0x_Anakin Jan 21 '13 at 22:43
  • Okay. But there are 2 parameters in the query: `$1 and $2`. To which key should be assigned the whole incoming query, `page` or `request`? – Felipe Alameda A Jan 21 '13 at 22:48
  • $_GET['request'] should have this state=3cb7a28b14112d3f3ecada3d6915ac5f&code=AQAZeWtJgz1ZYWvsorRPiMRetkNhnU3NrQ9KYzIRkogUpg6IPHCkFCAWMBUYGYtulfWnr5JHWs2GbrBUAp89pVLStyKs_rer2r14yLI6qdByoqEv1TtHGK4TPzdLFRTgXZEzPEUyk9ixYQfdmZid0dRdTfVXDPqniCKnu8RHQb1ErRDezsdI2CcYsTxofe_wwtZYVD3d4r9VtlANrGn_klP1#_=_ – 0x_Anakin Jan 21 '13 at 22:50
  • The regex in the rule is designed to match other string structures and to split them. You would have to modify it to do what you need, along with the whole rule. But, if you do it the other URLs won't match. – Felipe Alameda A Jan 21 '13 at 22:53
  • Is there any way I could replace ? with & in the url through htaccess ? – 0x_Anakin Jan 21 '13 at 23:02
  • Yes, but if you do it it will modify all the URL and the worst part is queries will cease to be queries as `?` is what identifies them. So, it is not a good idea. – Felipe Alameda A Jan 21 '13 at 23:06
  • I've come up with another solution. I could validate and process $_SERVER['REQUEST_URI'] I suppose that would work.. so that I can extract tha info i need without messing with the htaccess rules – 0x_Anakin Jan 21 '13 at 23:12
  • 1
    That's a practical solution. Rewrite rules should not be used to solve the type of problem you are facing. – Felipe Alameda A Jan 21 '13 at 23:21

1 Answers1

-1

Your first sub-pattern ([^/]*) is a greedy pattern. This means that the expression will match the largest possible substring of the input string (and since the expression matches everything except the / character, it will match the entire string -- subsequently, the second sub-pattern will not match anything).

You can mark the subpattern as non-greedy or lazy (i.e. ([^/]*?)), but then it will match only the /character. You could modify the pattern to match everything up to the beginning of the query part of the URL: ^([^/]*?)\?

helmbert
  • 35,797
  • 13
  • 82
  • 95