views:

35

answers:

3

What is wrong with this rewrite rule?

RewriteRule ^api/(.+)$ api/index.php?url=$1 [L]

I simply want "index.php?url=" to be added after api/ and before the rest of the get parameters.

api/image/upload&arg1=1&text=lorem+ipsum

to

api/index.php?url=image/upload&arg1=1&text=lorem+ipsum

What is wrong with (.+) to get everything after api/?

A: 

Are you doing something to stop infinite recursion?

 RewriteRule ^api/(.+)$ api/index.php?url=$1 [R=301,L]

or some equivalent

Lou Franco
I had [L] before but it does not make any diffrence. My problem is that apache2 reports that the only get parameter is [url] => index.php , all other parameters are gone and url parameter should be 'image/upload'. When I use the rule ^api/([a-zA-Z0-9/_]+)$ instead the url parameter is 'image/upload' but I loose all other GET parameters instead.
Tirithen
Tirithen
A: 

I think you must write your domain name before the regex stuff. Like this:

RewriteRule ^(.+).com/api/(.*)$ "$1.com/api/index.php?url=$2" [R=301,L]
Erik Escobedo
+1  A: 

The regex on the RewriteRule is only run against the path part of the URL, not the query parameters. Fortunately there is the [QSA] flag to preserve existing query parameters.

hobbs
Wonderful! This solved my problems! I have allso found a JS function to url encode all non a-zA-Z0-9_. characters http://cass-hacks.com/articles/code/js_url_encode_decode/
Tirithen