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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.