Andy-H Posted January 10, 2012 Share Posted January 10, 2012 I was wondering if anyone knew how I could rewrite a url so that anything after /{id}/{key}/{method} is appended as arg[]=$4&arg[]=$5 etc.. So if you were to request http://host/1/argh-argh-argh-argh/getItem/1/5/8/4 It would rewrite to http://host/index.php?shopID=1&APIkey=argh-argh-argh-argh&method=getItem&arg[]=1&arg[]=5&arg[]=8&arg[]=4 I have done it before for /page/test/test/test/test // to ?page=$1&$2=$3&$4=$5 but looking back, don't recall how it works, here is the code: <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{QUERY_STRING} ^$ RewriteRule ^(.+)/([^/]+)/([^/]+)$ $1?$2=$3 [QSA,E=TEST:$1] RewriteCond %{ENV:TEST} ^(.+)/([^/]+)/([^/]+)$ RewriteRule ^.*$ %1?%2=%3 [QSA,E=TEST:%1,N] RewriteCond %{ENV:TEST} ^([^/]+)$ [OR] RewriteCond %{REQUEST_URI} ^([^/+])/(.+)$ RewriteRule ^.*$ control.php?page=%1&%2 [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]*)$ control.php?page=$1 [NC,L] </IfModule> Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/254715-loop-rewrite/ Share on other sites More sharing options...
Andy-H Posted January 10, 2012 Author Share Posted January 10, 2012 Managed it <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{QUERY_STRING} ^$ RewriteRule ^(.+)/([^/]+)/([^/]+)/([^/]+)$ $1/$2/$3/?arg[]=$4 [QSA,E=TEST:$1/$2/$3] RewriteCond %{ENV:TEST} ^(.+)/([^/]+)/([^/]+)/([^/]+)$ RewriteRule ^.*$ %1/%2/%3?arg[]=%4 [QSA,E=TEST:%1/%2/%3,N] RewriteCond %{ENV:TEST} ^([^/]+)/([^/]+)/([^/]+)$ [OR] RewriteCond %{REQUEST_URI} ^([^/+])/([^/+])/(.+)$ RewriteRule ^.*$ index.php?shopID=%1&APIkey=%2&method=%3 [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?shopID=$1&APIkey=$2&method=$3 [NC,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]*)/([^/]*)$ index.php?shopID=$1&APIkey=$2 [NC,L] </IfModule> Quote Link to comment https://forums.phpfreaks.com/topic/254715-loop-rewrite/#findComment-1306084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.