You can do that in just a single rule. Place this in your /me/.htaccess
folder:
RewriteEngine On
RewriteBase /Me/
RewriteRule ^(data|Scripts/handler\.php)/([^/]+)/([^/]*)(/.*)?$ Scripts/handler.php/$4?$2=$3 [L,QSA,NC]
Pergunta
I know somehow you can have a url such as foo.com/me/data/key1/val1/key2/val2
with a random amount of key/value pairs in it. I assume it is a recursive rule needed to accomplish this, but so far I have:
RewriteRule ^(data)/([^/]*)/([^/]*)(/.*)?$ /$1/$4?$2=$3 [L,QSA,NC]
RewriteRule ^(data)/(/[^/]+|[^/]+/|/?)$ /datahandler.php [L,QSA]
But this isn't working. I get a 404 error. I need the data
part of the url to distinguish it from any other requests.
This is the current structure of the site:
Site Root
- .htaccess (1)
- index.php
- /Me
- - .htaccess(2)
- - index.php
- - /Scripts
- - - handler.php
The content of the htaccess files:
.htaccess (1)
RewriteEngine On
RewriteRule ^Me/?(.*)$ /Me/$1 [NC,L]
.htaccess (2)
RewriteEngine On
RewriteRule ^(data)(?:Scripts\/handler\.php)?/([^/]+)/([^/]*)(/.*)?$ /$1Scripts/handler.php/$4?$2=$3 [L,QSA,NC]
Solução
You can do that in just a single rule. Place this in your /me/.htaccess
folder:
RewriteEngine On
RewriteBase /Me/
RewriteRule ^(data|Scripts/handler\.php)/([^/]+)/([^/]*)(/.*)?$ Scripts/handler.php/$4?$2=$3 [L,QSA,NC]
Outras dicas
Try:
RewriteRule ^(data)/([^/]+)/([^/]+)(?:/(.+)|)$ /$1/$4?$2=$3 [L,QSA,NC]
RewriteRule ^(data)/?$ /datahandler.php [L]
The first rule you got right, but the second rule has too many slashes.