A
A
Andrew Dabich2014-01-10 12:26:29
PHP
Andrew Dabich, 2014-01-10 12:26:29

How to send array by get method via .htaccess redirect?

You need to send an array of parameters like /index.php?array[1]=1&array[2]=2&array[3]=3 with a redirect.
Something like this:
RewriteRule ^page/?$ index.php?array=$1 [L,QSA]
But the regular expression needs to be correct to pass the parameters. And what is the best way to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Flaker, 2014-01-10
@Flaker

You can do this index.php?array[1]=1&array[2]=2&array[3]=3 , without rewrite in htaccess , then in the $_GET array, by the array key, you will have an array " 1, 2, 3 ".
I don't quite understand why you need rewrites.
Usually, they are used to organize CNC .
Let's say:
In this case, everything after site.ru/ will be redirected to index.php as a GET request. In the $_GET array, this string will be located by the route key.
That is, in order to make an array out of it, you will have to parse this line ( Actually, this is what routing does in the MVC pattern ).
Roughly speaking, you can do this:

$route = $_GET['route'];
$array = preg_split('/\//', $route);

Now, with such a request " site.ru/1/2/3 ", the $array will contain the elements " 1, 2, 3 ".
In general, a normal rewrite is written like this:
# Activates URL rewriting
RewriteEngine on

# Allow file access
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite rules
RewriteRule ^(.+)$ index.php?route=$1 [L,QSA]

This takes into account access to files directly.

S
svd71, 2014-01-10
@svd71

RewriteCond %{REQUEST_FILENAME} !/index.php$
RewriteRule ^(.*)$ index.php?array=$1 [L,QSA]

Upd: edited a bit (it's hard to look at raws in another computer and type at the same time :-))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question