perqedelius perqedelius - 4 months ago 11
PHP Question

htaccess redirect URL with sub directories to php file

I need to redirect a Specific root URL (in this example "test") with unknown sub directories to a php file.

example URL

I have tried with this .htacces code

RewriteRule ^test(/.*)?$ redirect.php?path=$1


I use this code to split the $path

$path = explode("/", $_GET['path']);

But when I run print_r on $path in my redirect.php file array 0 is empty

Array ( [0] => [1] => sub1 [2] => sub2 )

How can I get the full path in my array?


If you want to capture full path then use RewriteCond with REQUEST_URI variable:

RewriteCond %{REQUEST_URI} ^/(test(?:/.*)?)$ [NC]
RewriteRule ^ redirect.php?path=%1 [L,QSA]