Jump to content

Loop rewrite


Andy-H

Recommended Posts

 

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.

Link to comment
https://forums.phpfreaks.com/topic/254715-loop-rewrite/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/254715-loop-rewrite/#findComment-1306084
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.