Alauddin Ansari
Alauddin Ansari

Reputation: 250

Need htaccess rule to differentiate directories and query strings

I've an url like below mentioned.

abc.com/test/abc/hello/?hello=world&foo=bar

I've to differentiate directories and query string separate using htaccess

I need to have result like:

Array
(
    [data] => test/abc/hello/
    [hello] => world
    [foo] => bar
)

I've tried many htaccess methods but won't got the result what I want. I've tried below methods

If I tried:

RewriteRule ^([\w\-\/]+)$ index.php?data=$1

Output:

Array
(
    [data] => test/abc/hello/
)

And when tried:

RewriteRule .* test.php [L]

Output:

Array
(
    [hello] => world
    [foo] => bar
)

But suggest me htaccess rule from which I can get result like

Array
(
    [data] => test/abc/hello/
    [hello] => world
    [foo] => bar
)

Can anybody help me to get my results from htaccess

Upvotes: 1

Views: 68

Answers (1)

jacouh
jacouh

Reputation: 8741

This may work (Not TESTED):

RewriteEngine On
RewriteRule ^([\w\-\/]+)$ index.php?data=$1 [L,QSA]

Flag QSA: QueryString Appended.

But I'm rather reserved as you use this to get data, hello and foo, it's too costful. In PHP you can use this:

<?php
$data = $_SERVER["REQUEST_URI"];
$hello = $_GET["hello"];
$foo = $_GET["foo"];
?>

Without any Rewriting required.

Upvotes: 1

Related Questions