I want to have a url like http://localhost/folder1/folder2/folder3/file Then i want mod_rewrite to convert it to $_GET['d'] in the url it would look like d[]=folder1&d[]=folder2&d[]=folder3
Is this possible?
Thank You.
Yes it is possible:
RewriteRule ^(([^/]+/)*)([^/]+)/([^/]+)$ /$1$4?d[]=$3 [QSA,N]
RewriteRule ^([^/]+)$ - [L]
But mod_rewrite is not really suited for that kind of work. In fact, you can quickly create an infinite loop with the N flag.
You should rather use PHP to extract the requested URL path its segments:
$path = strtok($_SERVER['REQUEST_URI'], '?');
$segments = implode('/', ltrim($path, '/'));
Then use this single rule to rewrite the requests to your file:
RewriteRule ^([^/]+/)+([^/]+)$ $2 [L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With